Created
May 10, 2010 08:03
-
-
Save littlefolk/395798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
""" | |
http://www.fujitv.co.jp/heisei/04.html | |
(問) | |
8個の数字の配列の規則を見つけ、 | |
?に入る数を答えなさい | |
→ 4 → 16 → 37 → 58 → 89 → 145 → 42 → ? ↓ | |
↑←←←←←←←←←←←←←←←←←←←←←←←← | |
""" | |
def heisei(i): | |
def f(i): | |
return reduce(lambda x, y: x + y, map(lambda x: int(x) ** 2, list(str(i)))) | |
while True: | |
i = f(i) | |
yield i | |
End = {1: [1], 4: [4]} | |
for i in range(2, 100): | |
print i | |
t = heisei(i) | |
buf = [i] | |
while True: | |
res = t.next() | |
buf.append(res) | |
if res == i: | |
End[res] = End.setdefault(res, []) + [i] | |
print "GOAL" | |
break | |
elif res in End.keys(): | |
End[res] = End.setdefault(res, []) + [i] | |
print "Endless Loop (%i)" % res | |
break | |
print buf | |
print End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment