def islychrel(n): for _ in range(50): nr = int(''.join(reversed(str(n)))) s = n + nr if ispalindromic(str(s)): return False else: n = s return True
def islychrel(n): for _ in range(50): nr = int("".join(reversed(str(n)))) s = n + nr if ispalindromic(str(s)): return False else: n = s return True
for b in range(10)] +\ ['%d%d%d%d' % (a,b,b,a) # 90 4-digit, same as 3-digit for a in range(1,10) for b in range(10)] +\ ['%d%d%d%d%d' % (a,b,c,b,a) # 900 5-digit for a in range(1,10) for b in range(10) for c in range(10)] +\ ['%d%d%d%d%d%d' % (a,b,c,c,b,a) # 900 6-digit, same as 5-digit for a in range(1,10) for b in range(10) for c in range(10)]) # This is much more efficient print sum(i for i in palindromicnumbers() if i%2 and ispalindromic(dec2bin(i))) # now I'm going to write it like crazy Lisp-ist ... def palindromic(n): ''' Generate palindromic numbers containing n digits ''' return range(10) if n==1 else map(int, ('%d'*n % (comb + comb[::-1][n%2:]) for comb in reduce(lambda ts, es: [t+(e,) for t in ts for e in es], [[(t,) for t in range(1,10)]] + [range(10)]*(sum(divmod(n,2))-1)))) print sum(each for each in reduce(lambda x,y: x+y, (palindromic(i) for i in range(1,7))) if each % 2 and ispalindromic(dec2bin(each)))
['%d%d%d%d' % (a,b,b,a) # 90 4-digit, same as 3-digit for a in range(1,10) for b in range(10)] +\ ['%d%d%d%d%d' % (a,b,c,b,a) # 900 5-digit for a in range(1,10) for b in range(10) for c in range(10)] +\ ['%d%d%d%d%d%d' % (a,b,c,c,b,a) # 900 6-digit, same as 5-digit for a in range(1,10) for b in range(10) for c in range(10)]) # This is much more efficient print sum(i for i in palindromicnumbers() if i % 2 and ispalindromic(dec2bin(i))) # now I'm going to write it like crazy Lisp-ist ... def palindromic(n): ''' Generate palindromic numbers containing n digits ''' return range(10) if n == 1 else map( int, ('%d' * n % (comb + comb[::-1][n % 2:]) for comb in reduce(lambda ts, es: [t + (e, ) for t in ts for e in es], [[(t, ) for t in range(1, 10)]] + [range(10)] * (sum(divmod(n, 2)) - 1))))
from euler import ispalindromic print max(i*j for i in range(100,1000) for j in range(100,1000) if ispalindromic(str(i*j)))