uokadaの見逃し三振は嫌いです

ここで述べられていることは私の個人的な意見に基づくものであり、私が所属する組織には一切の関係はありません。

コラッツ問題を簡単にといてみた。

コラッツの問題 - Wikipedia

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

def Collatz(x):
    result = [x]
    while not x == 1:
        if x % 2 == 0:
            x = x/2
        else:
            x = x*3+1
        result.append(x)
    return result

max_num = 1
max_times = 0
for item in range(1,100000):
    res = Collatz(item)
    if max_times < len(res):
        max_num = item
        max_times = len(res)
        print item, len(res)

print "MAX : ", max_num, max_times
% python2.7  collatz.py
1 1
2 2
3 8
6 9
7 17
9 20
18 21
25 24
27 112
54 113
73 116
97 119
129 122
171 125
231 128
313 131
327 144
649 145
703 171
871 179
1161 182
2223 183
2463 209
2919 217
3711 238
6171 262
10971 268
13255 276
17647 279
23529 282
26623 308
34239 311
35655 324
52527 340
77031 351
MAX :  77031 351