Project Euler 92(python, 3minutes)....
完全に敗北です。
くそコードだけども、仕方ない。
999999 -> 567だと気づけばもっと早いコードがかける。
が、考慮しても30秒しな縮まらず敗北感。
#-*- coding:utf-8 -*- from datetime import datetime def square_count(x, List1, List2): count_square = [] search = x while True: Next = sum([int(i) ** 2 for i in list(str(search))]) if (Next == 89) or (Next in List1): if Next == 89: List1 += count_square return True if (Next == 1) or (Next in List2): if Next == 1: List2 += count_square return False count_square.append(Next) search = Next def Euler92(): N = 10 ** 7 counter = 0 count_true = [] count_false = [] for n in xrange(1, N): if square_count(n, count_true, count_false): counter += 1 return counter def main(): start = datetime.now() answer = Euler92() end = datetime.now() print end - start, answer if __name__ == "__main__": main()