# 2020-10-02 Collatz

## 603 days ago by calkin

The Collatz conjecture.

Define $f(n) = n/2$ if $n$ is even, and $3n+1$ if $n$ is odd.

(Parenthetical silly question: what do we see if we make $n/2$ if $n$ is odd and $3n+1$ if $n$ is even?  Need to say what to do if $n$ is not an integer)

The Collatz conjecture says that for all $n$, for sufficiently large $k$, $f^k(n) \in \{1,2,4\}$.

We can track how many iterations it takes to reach 1.

Define $h(n)$, the hailstone function, to be the number of iterations it takes for $n$ to reach 1.

Compute a list of values $[n,h(n)]$.

Plot this for various ranges of $n$.

Finding champions.

A number $n$ is a champion if $h(n)>h(k)$ for all $k<n$, that is, if it has the largest $h$ value we've seen so far.

So, for example, 27 is champion.

Write code to do the following:

Set up an empty list of champions

Set the current maxh to -1

For each $n$, if $h(n)>$ maxh, replace maxh by $h(n)$, and append $n$ to the list of champions.