Enigmatic Code

Programming Enigma Puzzles

Enigma 231: Six of the best

From New Scientist #1377, 29th September 1983 [link]

I was constantly being kept in at school to do extra work on decimals. So many unhappy memories are revived now that my son brings home his decimal homework: but thank goodness for calculators!

Unfortunately, the homework calls for exact answers, but my calculator displays only six digits after the decimal point. But that was no disadvantage for last night’s homework. For the teacher had listed all the integers greater than 1 whose reciprocals were recurring decimals such that the first six digits occurring after the decimal point occurred again in that order as the 7th-12th digits and the 13th-18th etc. So, for example, the first two numbers in the list were 3 and 7 because ⅓=0.3333333333333… and ⅐=0.142857142857… My son’s homework was to work out the decimals of all the reciprocals. So, for once, my limited calculator display was sufficient to check his answer.

How many numbers had the teacher listed?

Note: I am still waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment. The latest estimate is that I’ll have a connection by the end of October 2014.



One response to “Enigma 231: Six of the best

  1. Jim Randell 20 October 2014 at 1:32 pm

    This Python program runs in 32ms.

    from enigma import divisors, printf
    # if: 1/n = 0.abcdefabcdef...
    # then: 1000000/n = abcdef.abcdefabcdef...
    # so: 999999/n = abcdef
    # and: n = 999999/abcdef
    # so we need to count the divisors of 999999, greater than 1
    t = 0
    for n in divisors(999999):
      if n > 1:
        t += 1
        printf("[n={n} {x:06d}]", x=999999 // n)

    Solution: The teacher had listed 63 numbers.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: