Skip to content

Instantly share code, notes, and snippets.

@rainzoo
Last active December 25, 2015 06:19
Show Gist options
  • Save rainzoo/6931123 to your computer and use it in GitHub Desktop.
Save rainzoo/6931123 to your computer and use it in GitHub Desktop.
Champernowne's constant https://projecteuler.net/problem=40
def champ(n):
s = ""
for x in xrange(0,n+1):
s = s + str(x)
return int(s[n])
k = [1, 10, 100, 1000 ,10000, 100000, 1000000]
ans = 1
#either
for i in k
ans = ans * champ(i)
# or
ans = reduce(lambda x,y: x*y, map(champ, k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment