### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,114)
- misc (2)
- project euler (2)
- puzzle (29)
- site news (43)
- tantalizer (29)
- teaser (3)

### Site Stats

- 166,224 hits

Programming Enigma Puzzles

9 February 2012

Posted by on **From New Scientist #2742, 9th January 2010** [link]

I have written down three 3-digit numbers which between them use nine different digits. One of the numbers is a perfect square and another is a triangular number. The sum of the three numbers is 2010.

What, in ascending order, are the three numbers?

[enigma1577]

Advertisements

%d bloggers like this:

The following Python program runs in 38ms.

Solution:The numbers are: 325, 784 and 901.Here is a Picat port of @geoffrounce MiniZinc model. It runs in about 18ms.

Picat don’t support MiniZinc’s nice syntax of “in” in

However, it can be simulated by the uglier ” X :: Sq3 # 1″. The “fail” predicate ensures that there’s a unique solution.

Below are two different approaches. go2/0 is also a plain CP model and is actually some milliseconds faster than go/0, but not as neat. go3/0 is a hybrid where the perfect square and triangle number conditions are calculated after solve/2. It’s about as fast as go/0.

Here’s a solution using the

SubstitutedExpression()alphametic solver from theenigma.pylibrary. This run files executes in 94ms.The

--templateand--solutionparameters neaten up the output and are not necessary to solve the problem. The--answerparameter ensures the solution numbers are given in ascending order.