Matthias Dittgen

August 10, 2021

Collatz conjecture

Today at Hacker News»

Do you like Math? And have you heard about 3n+1, yet? I just figured it out today, when it was in the top 100 at Hacker News, so I stumbled over this youtube video about ‘The Simplest Math Problem No One Can Solve’.

There are different names for this row algorithm and you can probably look up more informations on this on your own. I was immediately interested in making some visual coding and ‘feel the numbers’ all by myself, the seemingly random peaks on the one hand and the always exact same ending on the other.

You might get the nobel prize in mathematics if you can prove, why this row ends for all numbers at 1. Or you find a number that gets caught in a loop and never reaches 1?

Visualization»

I’ve created these three visualizations/animations as Svelte components. I came up with the idea to show the steps as fragments of a circle to see if there’s some hidden pattern. ;)

7∙3 + 1
7
7

Algorithm»

The rules for a Collatz row are so simple: Pick a number and if it is

Repeat and you’ll always end at number 1.

In terms of Javascript code, it’s so simple as well.

const applyRules = (num) => (num & 1) ? num * 3 + 1 : num / 2;

CAUTION: Addictive»

But before you worry about it now yourself, be warned, some say this topic could quickly become addictive. There’s of course already a xkcd for the Collatz conjecture, too.

XKCD Comic about the Colatz Conjecture

1
2
4
8
16
32
5
64
10
128
21
20
3
42
40
6
84
80
13
12
168
160
26
24
53
52
48
106
104
17
96
35
34
192
70
68
11
140
23
136
22
46
45
44
7
92
15
90
88
14
184
30
180
176
29
28
61
60
58
56
9
122
120
116
19
112
18
38
37
36
76
74
72
152
25
148
144
50
49
100
98
200
33
196
66
65
132
130
43
86
172
57
114