The Collatz conjecture states that every positive integer will — if you iteratively set to — result in (function shown beneath).

The graph beneath shows the path length of numbers from to . In this range is the number with the most steps, .

```
# Python 2.7.7 Code
# Pygame 1.9.1 (for Python 2.7.7)
# Jonathan Frech 2nd of September, 2016
```

```
# import
import pygame, math, os
# steps to 1
def pathlen(k):
l = 0
while k != 1:
k = [k/2, 3*k+1][k%2]
l += 1
return l
# create data
data = []
maxx = 10**4
for _ in range(1, maxx+1):
data.append(pathlen(_))
maxy = max(data)
# graph size, surface and scale factor
width, height = 1080, 720
graph = pygame.Surface([width, height])
scalex, scaley = float(width)/maxx, float(height)/maxy
# render data
for _ in range(0, len(data)):
pygame.draw.circle(graph, [255, 0, 0], [int(_*scalex), height-int(data[_]*scaley)], 4)
# save graph
pygame.image.save(graph, os.getcwd() + "/collatz.png")
# get the largest step count with steps
#print data.index(maxy), "->", pathlen(data.index(maxy)+1)
```