Find maximum value iterative
Posted: Sun Mar 17, 2024 4:40 pm
Find the maximum of as many input values as you want. The logic has 1. loop, 2. algorithm and 3. values.
To use the comb, give values. Each value has a combinator with condition "I = [next number]". The numeration starts from 1. Connect the combinators with green wire in the input and red wire in the output.
Set N in combinator (top left) to the number of values.
Turn R on and back off again to reset the max value.
The algorithm constantly loops and updates the max value.
The loop produces single ticks every three seconds, meaning 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, ..., n-1, 0, 0 and then starts from the beginning.
The algorithm calculates how much to add to the max value in order to update it. It updates it if the number is bigger than the max value. For example if the current max value is 7 and the currently processed number is 16, 7 is converted to -7, 16 is added to get 9 and 9 is added to the max number. (9 is > 0 : 16 is greater than 7). These are three operations and that is why the looop "waits" for the algorithm to finish befure it supplies the next number.
The values can be positive, negative, can have multiple items and the condition can become Everything > 0, Anything > 0, Everything < 0, and Anything < 0
Programming in Factorio. What a blast
To use the comb, give values. Each value has a combinator with condition "I = [next number]". The numeration starts from 1. Connect the combinators with green wire in the input and red wire in the output.
Set N in combinator (top left) to the number of values.
Turn R on and back off again to reset the max value.
The algorithm constantly loops and updates the max value.
The loop produces single ticks every three seconds, meaning 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, ..., n-1, 0, 0 and then starts from the beginning.
The algorithm calculates how much to add to the max value in order to update it. It updates it if the number is bigger than the max value. For example if the current max value is 7 and the currently processed number is 16, 7 is converted to -7, 16 is added to get 9 and 9 is added to the max number. (9 is > 0 : 16 is greater than 7). These are three operations and that is why the looop "waits" for the algorithm to finish befure it supplies the next number.
The values can be positive, negative, can have multiple items and the condition can become Everything > 0, Anything > 0, Everything < 0, and Anything < 0
Programming in Factorio. What a blast