### 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

5 January 2018

Posted by on **From New Scientist #1580, 1st October 1987** [link]

My Welsh friend, Dai the dial, has a telephone number consisting of nine different digits and, as you telephone him on my push-button phone illustrated above, you push a sequence of buttons each adjacent (across or down) to the one before.

The digit not used in his number is odd, the last digit of the number is larger than the first, and (ignoring the leading digit if it is zero) the number is divisible by 21.

What is Dai’s number?

[enigma430]

Advertisements

%d bloggers like this:

A nice straightforward Python 3.6 program executes in 42ms.

Run:[ @repl.it ]Solution:Dai’s phone number is 087412563.Here’s a MiniZinc model.

Hakan/Jim: An interesting MiniZinc solution

The last line of the Enigma description reads;

“The digit not used in his number is odd, the last digit of the number is larger than the first, and (ignoring the leading digit if it is zero) the number is divisible by 21.”

I can see the first constraint in this sentence is included in the code, but the other two constraints in this sentence do not seem needed in the code to find a solution ?

Also, in the array/ number conversion, why does the leading ‘0’ digit in the answer not get lost in the conversion to a number ?

@geoffrounce Thanks for your comments. Here are answers regarding the MiniZinc model.

1) The constraint about the last digit is larger than the first is not needed in the model (since the first number is 0). Though I have to admit that I forgot it.

2) The statement “the number (ignoring the leading digit if it’s zero) is divisible by 21” is a copy-paste mistake of mine in the code above. The constraint section should read as following, i.e. I omitted the last constraint:

Sorry about that!

3) “num” is converted to a proper number, so the leading 0 is ignored. Though, the answer is not printing “num”, but the full array (the “show(x[i]) | i in 1..n” in the output section).

The full model is here: http://hakank.org/minizinc/enigma_430_let_the_fingers_do_the_walking.mzn

Here’s my MiniZinc solution. I assign the digits (including the digit that is not used in the phone number) into the array [[

d]], indices d[1] – d[9] represent the phone number, d[10] is the unused digit.