How to resolve the algorithm Greatest element of a list step by step in the E 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 E 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 E programming language
Source code in the e programming language
pragma.enable("accumulator") # non-finalized syntax feature
def max([first] + rest) {
return accum first for x in rest { _.max(x) }
}
? max([1, 2, 3])
# value: 3
def max([var bestSoFar] + rest) {
for x ? (x > bestSoFar) in rest {
bestSoFar := x
}
return bestSoFar
}
? max([1, 3, 2])
# value: 3
? max([[1].asSet(), [2].asSet(), [1, 2].asSet()])
# value: [1, 2].asSet()
You may also check:How to resolve the algorithm Hilbert curve step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Currying step by step in the Rust programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Ada programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the Frink programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the REBOL programming language