### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

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

### Site Stats

- 175,242 hits

Advertisements

Programming Enigma Puzzles

17 March 2017

Posted by on **From New Scientist #1537, 4th December 1986** [link]

My niece was playing with my calculator recently. She showed me a three-figure number displayed (and I could see three different digits) and then she pushed the “square” button. This resulted in another number being displayed. I could see a number, but I soon realised that it was not the square of the original number.

On investigation we soon find out what was wrong. My calculator usually lights up the digits in this way:

that is, it lights up some of the seven little elements in each case. But we found out that the calculator had developed a fault. Although it did all its calculations correctly, in each place where a digit could be displayed the same one of the seven elements never lit up.

Some digits from 0 to 9 could still be lit up correctly, but over half of them couldn’t. Just that fact, together with knowing how many of the 10 digits could light up correctly, would enable you to work out which of the seven elements consistently failed.

If my calculator had been working correctly, what would I have seen displayed after the “square” button had been pushed?

[enigma388]

Advertisements

%d bloggers like this:

Like

Enigma 1232(a similar problem), this problem was also a bit more convoluted to code up than I originally expected.This Python program runs in 42ms.

Solution:If the calculator had been working correctly the square displayed would be 29929.On the broken calculator the upper-left vertical segment on each digit does not light up.

So the 3-digit number 173 (which displays as 173) when squared gives 29929, which is displayed as 23323 (which is not a square number).

The restriction that more than 5 of the digits are affected by the failure only rules out the failure of the lower-left hand vertical segment (which affects the four digits 0, 2, 6, 8), the remaining segments affect 6 or more digits, although, of these, only failure of the upper-left vertical segment (which affects 6 digits) and lower-right vertical segment (which affects 9 digits) are uniquely identified by the number of affected digits.

I use the

unpack()function in line 35 to allow the program to work in both Python 2 and Python 3.