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)
| 42 | |
| 43 | |
| 44 | def 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 | |
| 61 | if __name__ == "__main__": |
no test coverage detected