http://projecteuler.net/index.php?section=problems&id=25 The Fibonacci sequence is defined by the recurrence relation: Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 F6 = 8 F7 = 13 F8 = 21 F9 = 34 F10 = 55 F11 = 89 F12 = 144 The 12th term, F12, is the first term to contain three digits. What is the first term in the Fibonacci sequence to contain 1000 digits? """ from pe2 import fibs from pe12 import first s = first( lambda i_f : i_f[1] >= 10**999, enumerate(fibs()) )[0] + 1 #enum from 0 assert s == 4782
integer with (1,2, ... , n) where n 1? """ from itertools import permutations from pe12 import first ns = list(xrange(1,10)) digits = list(str(i) for i in xrange(9,0,-1)) def is_concatenated(p): digits = str(p) for i in xrange(1,5) : #at five digits it would not work first_term = int(digits[:i]) s = "" for n in xrange(1,9) : s += str(first_term*n) if digits == s : return True if not digits.startswith(s) : break return False assert is_concatenated(192384576) assert is_concatenated(918273645) # 9 # from the largest down mpd = first( lambda pd : is_concatenated(pd), ( int(''.join(p)) for p in permutations(digits)) ) assert mpd == 932718654