We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Am I the only one facing problem with this code....
Starting number with the longest Collatz sequence up to 20 is 18 but why is the compiler expecting the answaer to be 19?
18>9>28>14>7>22>11>34>17>52>26>13>40>20>10>5>16>8>4>2>1
Project Euler #14: Longest Collatz sequence
You are viewing a single comment's thread. Return to all comments →
Am I the only one facing problem with this code.... Starting number with the longest Collatz sequence up to 20 is 18 but why is the compiler expecting the answaer to be 19? 18>9>28>14>7>22>11>34>17>52>26>13>40>20>10>5>16>8>4>2>1
Yeah, I was facing that issue too. What happens here is that, for both 18 and 19 the length is same. So store the value which occur later.
For both 18 and 19 it is 21.
So, when your code store for 18, then in the next iteration, store for 19. Use something like lenght >= max_length