Collatz

Collatz sequence - maximum length in a range.

The Collatz sequence is a sequence of positive integers. The term after value=n is:

  • value = n/2 if n is even
  • value = 3*n+1 if n is odd

Example: 5 -> 16 -> 8 -> 4 -> 2 -> 1.

Source: Project Euler Problem 14.

Problem Statement

Find the number n < 1,000,000 that gives the longest chain (before hitting one).

Suggestion: Insert code to check for an impossible condition, say n<1 in your sequence generating function.

Last modified August 18, 2023: 2022-2023 End State (7352e87)