import matplotlib.pyplot as plt
def collatz(num, count = 0):
count += 1
if num == 1:
return count
if num % 2 == 0:
return collatz(num/2, count)
else:
return collatz((num * 3) + 1, count)
# グラフの作成
x = []
y = []
for i in range(1, 30):
x.append(i)
y.append(collatz(i))
fig, ax = plt.subplots(dpi=120)
ax.plot(x, y)
plt.show()
コラッツ予想って何?