MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_014/sol2.py:44–58  ·  view source on GitHub ↗

Returns the number under n that generates the longest Collatz sequence. >>> solution(1000000) 837799 >>> solution(200) 171 >>> solution(5000) 3711 >>> solution(15000) 13255

(n: int = 1000000)

Source from the content-addressed store, hash-verified

42
43
44def solution(n: int = 1000000) -> int:
45 """Returns the number under n that generates the longest Collatz sequence.
46
47 >>> solution(1000000)
48 837799
49 >>> solution(200)
50 171
51 >>> solution(5000)
52 3711
53 >>> solution(15000)
54 13255
55 """
56
57 result = max((collatz_sequence_length(i), i) for i in range(1, n))
58 return result[1]
59
60
61if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls 1

collatz_sequence_lengthFunction · 0.85

Tested by

no test coverage detected