Project Euler 63

Some more one liner fun.

I first had the program looking like this:-

total = 0
for x in range(1,10):
    for n in range(1,51):
        if n == len(str(x**n)):
            total += 1
print (total)

After a good look, I was able to reduce it to a 1 liner:-

import time
r = time.time()

print(sum(len(str(x**n)) == n for x in range(1,10) for n in range(1,51)))

print ( time.time() - r )

The parenthesis around print sure does require some getting used to.

Comments

comments powered by Disqus