Created
March 14, 2016 17:47
-
-
Save technicool/5c8354cdf449c90bb2e5 to your computer and use it in GitHub Desktop.
For Pizza Hut's problem on PI day 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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