Skip to content

Instantly share code, notes, and snippets.

@technicool
Created March 14, 2016 17:47
Show Gist options
  • Save technicool/5c8354cdf449c90bb2e5 to your computer and use it in GitHub Desktop.
Save technicool/5c8354cdf449c90bb2e5 to your computer and use it in GitHub Desktop.
For Pizza Hut's problem on PI day 2016
## For Pizza Hut's problem on PI day:
## http://blog.pizzahut.com/flavor-news/national-pi-day-math-contest-problems-are-here-2/
##
## I’m thinking of a ten-digit integer whose digits are all distinct. It happens that the
## number formed by the first n of them is divisible by n for each n from 1 to 10.
## What is my number?
##
def dnumber(digits, howmany):
number = 0
for i in range(0,howmany):
number = number * 10 + digits[i]
return number
def verify(digits):
for i in range(1,11):
dn = dnumber(digits, i)
mod = dn % i
if mod != 0:
return False
return True
def doDigitN(n, digits):
if n == 10:
if verify(digits):
print(digits)
exit()
return
for i in range(0,len(digits)+1):
newdigits = digits[:]
newdigits.insert(i, n)
doDigitN(n+1, newdigits)
doDigitN(0, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment