How to resolve the algorithm Greatest element of a list step by step in the Logo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest element of a list step by step in the Logo programming language
Table of Contents
Problem Statement
Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Greatest element of a list step by step in the Logo programming language
Source code in the logo programming language
to max :a :b
output ifelse :a > :b [:a] [:b]
end
print reduce "max [...]
to max [:inputs] 2
if emptyp :inputs ~
[(throw "error [not enough inputs to max])]
output reduce [ifelse ?1 > ?2 [?1] [?2]] :inputs
end
to bigger :a :b
output ifelse [greater? :a :b] [:a] [:b]
end
to max :lst
output reduce "bigger :lst
end
You may also check:How to resolve the algorithm A+B step by step in the Self programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the Scala programming language
You may also check:How to resolve the algorithm Semordnilap step by step in the Python programming language
You may also check:How to resolve the algorithm GUI enabling/disabling of controls step by step in the Ada programming language
You may also check:How to resolve the algorithm Enforced immutability step by step in the Scala programming language