Home > OS >  Maximum Collatz length in Python, but output is not correct
Maximum Collatz length in Python, but output is not correct

Time:03-23

This is my first time posting to Stackoverflow.

I'm trying to solve this problem here: enter image description here

However, I'm not sure where this goes wrong - I checked line-by-line and couldn't see anything wrong. Could anyone help me fix this? Thank you!

CodePudding user response:

I see what is wrong - hailLen returns lenght of sequence and the question is about index for which the sequence is the longest. Just store it in variable

if (res := hailLen(i)) > counter: # it's python 3.8 syntax
    counter = res
    index = i
return index
  • Related