Advertisement
ploffie

narcissistic version 1

Dec 14th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. from itertools import combinations_with_replacement
  2. from time import clock
  3.  
  4. t0 = clock()                    
  5. numbers = "0123456789"
  6. for n in xrange(1, 40):
  7.     print "n=", n, clock() - t0
  8.     if n in [2,12,13,15,18,22,26,28,30,36]: continue
  9.     pows = dict(zip(numbers, [i ** n for i in range(10)]))
  10.     mini, maxi  = 10 ** (n-1), 10 ** n
  11.     for digits in combinations_with_replacement(numbers, n):
  12.         sumpows = sum([pows[d] for d in digits])
  13.         if mini <= sumpows < maxi and tuple(sorted(str(sumpows))) == digits:
  14.             print sumpows, clock() - t0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement