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

20 June 2015

Posted by on **From New Scientist #2380, 1st February 2003** [link]

If you start with my age, in years, and apply the four operations:

in some order, then the final answer you get is my husband’s age in years.

Funnily enough, if you start with his age and apply the same four operations in a different order, then you get my age.

What are our two ages?

[enigma1224]

Advertisements

%d bloggers like this:

I assumed the couples ages were between 16 and 112.

This Python program runs in 50ms.

Solution:The couple are aged 48 and 53 (although we don’t know which age applies to the husband and which to the setter).The transitions between the two ages are given below:

In the published solution it gives the setters ages as 48 and the husbands age as 53, but I don’t see any way to distinguish the ages.

Here are two other, and different, approaches:

1) Constraint Programming with MiniZinc: http://hakank.org/minizinc/age_changing.mzn

Note: Just few FlatZinc solvers can handle mixed var int and var floats: Gecode, JaCoP, and G12 mip. Gecode solves this in 23ms (and with symmetry breaking that “my age” <="husbands age": 5ms).

2) Picat: http://hakank.org/picat/age_changing.pi

Two variants: go/0 use string parsing and go2/0 use functional + logic approach. However, both models use non-deterministic predicate such as between/3, permute/2.

Solve time is around 200ms.