Sunday, March 20, 2016

Lorenz Attractor

Processing / Lorenz Attractor

Monday, March 14, 2016

Pizza Pi Day Puzzle, Problem 1

ConwayTenDigitPuzzle

The John Conway / Pizza Hut problems for Pi Day

http://blog.pizzahut.com/flavor-news/national-pi-day-math-contest-problems-are-here-2/

Problem 1

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?

In [1]:
import itertools

Initial Observations

  • The 10th digit must be zero.
  • The 5th digit must then be 5.
  • The digits in positions 2,4,6,8 must be even
  • The digits in positions 1,3,7,9 must be odd
  • The digit in position 4 must be a 2 or 6

Secondary Observations

  • The first digit can be anything
  • The ninth digit can be anything
  • Given all the above conditions, the only positions that need to be checked are n=3,6,7,8
  • There will be 288 candidates to be checked (12 even permutations x 24 odd permutations)
In [2]:
def check_nth_slice(workstring,n):
    if int(workstring[:n])%n==0: 
        return(True)
    else:
        return(False)
    
for even in itertools.permutations(['2','4','6','8']):
    if (even[1]=='2' or even[1]=='6'):
        for odd in itertools.permutations(['1','3','7','9']):
            candidate=odd[0]+even[0]+odd[1]+even[1]+'5'+even[2]+odd[2]+even[3]+odd[3]+'0'
            if check_nth_slice(candidate,3) and check_nth_slice(candidate,6) and \
            check_nth_slice(candidate,7) and check_nth_slice(candidate,8):
                print(candidate)
3816547290