### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 177,972 hits

Advertisements

Programming Enigma Puzzles

21 April 2015

Posted by on **From New Scientist #2395, 17th May 2003** [link]

Joe took a sheet of lined paper and asked me to write a whole number on the first line. This I did, writing a number that was less than a million and which consisted of the same digit repeated several times. After some elaborate calculations Joe wrote a number of the second line. After more calculations he wrote a number on the third line, and he continued like this until he had written a huge number on the eighth line. I asked him how he calculated each number. He explained, “If the number N is on one line then I work out the remainders when N is divided by 5 or 6. In some cases the first remainder was larger than the second and in those cases I wrote the square of N+1 on the next line. In the other cases the first remainder was smaller than the second and I wrote the cube of N+2 on the next line.”

What number did I write on the first line?

[enigma1239]

Advertisements

%d bloggers like this:

This Python program runs in 32ms.

Solution:The number on the first line is 5555.I found this to be a poorly worded puzzle, as I think the challenge should be to solve a well specified problem, rather than try to work out what the problem actually is. At first I thought there wasn’t enough information to arrive a unique answer, but if we take the following clarifications then we can arrive at a unique answer. First we take the statement “I work out the remainders when N is divided by 5 or 6” to mean “I work out the remainder when N is divided by 5

andthe remainder when N is divided by 6″ (we call these two values the residues). We note that “in some cases the first remainder was larger than the second… in the other cases the first remainder was smaller than the second”. So what happens if the two residues are equal? We are not given a way to calculate the number that would be written down in this situation, so we can only assume that in the particular instance we are dealing with this never happens.This gives us a way to attack the problem. Of all the possible numbers composed of “several” (by which I’m assuming “more than two”) repeated digits, less than a million (so no more than 6 repeated digits), we are only interested in the ones where when the procedure followed is applied seven times (to give a total of eight numbers on the paper), none of the numbers have the same residue modulo 5 as modulo 6.

Assuming that “the square of N+1” is interpreted as (N+1)², and “the cube of N+2” as (N+2)³, we find that there is in fact only one possible initial number for which this is the case. (The program is written to select the largest final number from all the possibilities found, as we are just told that the final number is “huge”. Although it turns out there is only a single candidate number anyway). I also assumed that “in some cases the first remainder was larger than the second” implied that there must be multiple occurrences when this was the case, and likewise “in the other cases” implies that there must also be multiple occurrences when the first remainder is smaller than the second, so my program takes this into account, and the single possibility does indeed satisfy this condition.

However the “huge” number we end up with is 1618 digits, so even if Joe managed to squeeze each digit into a millimetre wide space the sheet of paper would have to be over 5 feet wide, which seems a little unlikely. A standard sheet of A4 is 210mm, so I think Joe would struggle to write out the numbers after the 4th application of the procedure. The digit lengths of the numbers being: 4, 12, 23, 68, 135, 270, 809, 1618.

Yes, same answer, testing all the possible 3,4,5, and 6 digit numbers less than 1 million.