(shit, the greater and lesser signs disappeared in my previous comment, and the spaces for indentation too... It's the first time I comment on this website, sorry. I hope it's still clear tho) |
==> |
I haven't even looked into the code yet, but I found a pattern.
Of course, I'm not 100% sure I'm right, but I haven't been wrong for now.
The program seems to count the numbers you input, but a number is ONLY counted if it's greater than a previous one.
Example:
./listen-to-your-heart 1 2 3 4 5
returns 5, because 2 is greater than 1, 3 is greater than 2, 4 is greater than 3 and 5 is greater than 4, so the counter is incremented 5 times.
But, if we run this:
./listen-to-your-heart 34 36 35 37
that returns 3, because:
-the counter is initialised at 1 (with the input 34)
- +1, because 3634
- +0, because 35 is not greater than 36
- +1, because 3736
I tested this with multiple inputs, of different values, and it worked each time.
So if I had to quickly rewrite the algorithm:
--------------
inputs = list of inputs
max = inputs[0]
counter = 1
for i in inputs:
if i not an integer:
display "Only Integers!"
exit
if imax:
max = i
counter += 1
display counter
exit
------------------------ |
==> |