### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,130 hits

Programming Enigma Puzzles

20 June 2016

Posted by on **From New Scientist #2318, 24th November 2001** [link]

Harry and Tom each chose a four-digit number that was either a perfect square or a triangular number and told me its last two digits. I deduced that Harry’s number was one of exactly two four-digit perfect squares or one of exactly two four-digit triangular numbers, but that Tom’s number was one of exactly three four-digit perfect squares or one of exactly three four-digit triangular numbers.

Then they told me that the sum of the digits of Harry’s number was the same as the sum of the digits of Tom’s number.

What were (a) Harry’s number and (b) Tom’s number?

[enigma1162]

%d bloggers like this:

This Python program runs in 34ms.

Solution:(a) Harry’s number was 5041. (b) Tom’s number was 1081.Is there a different solution? Harry 5041, Tom 2116, 2116 being the only square with digit sum 10 among groups of three squares that share the same last two digits.

There are three triangular numbers with digit sum 10 that are in groups of three that share the same last two digits – 1711 with 2211-8911, 1540 with 3240-7140 and 1081 with 3081-7381. It seems that Tom’s 1081 is not unique in the way that is required.

Tom might have said that his last two digits were 11 or 40 or 81 but, since we don’t know what he said, we cannot see a way to choose between them. On the other hand we can find a solution if we assume that Tom had said that his last two digits were 16.

Or have I got my arithmetic and/or logic wrong?

When were are looking groups of numbers that share the same last 2 digits we haven’t been told that the numbers share a digit sum. So we can’t use that information at that stage.

If we were told that Tom’s number ended in 16 then we can narrow it down to one of three squares (2116, 2916, 9216), but it could be one of four triangular numbers (2016, 3916, 6216, 9316). So Tom can’t have said his number ended in 16.

In fact Harry has to have a number ending in 41 (the only possibility that has two squares (5041, 6241) and two triangular numbers (3741, 6441)) and Tom has to have a number ending in 81 (the only possibility that has three squares (1681, 3481, 8281) and three triangular numbers (1081, 3081, 7381)).

The possible digits sums for Harry are 10 (5041), 13 (6241) and 15 (3741, 6441), and the possible digit sums for Tom are 10 (1081), 12 (3081), 16 (1681, 3481) and 19 (7381, 8281). So the common sum must be 10, and the actual numbers chosen follow.

Thanks so much for your trouble. Happy now.