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

27 March 2019

Posted by on **From New Scientist #1077, 10th November 1977** [link]

There are three tribes on The Island of Imperfection, the Pukkas who always tell the trith, the Wotta-Woppas who never tell the truth, and the Shilli-Shallas who make statements which are alternately true and false or false and true.

This story deals with four men whom we shall call

A,B,C, andDand there is at least one representative of each tribe among them.They make statements in accordance with their tribal characteristics as follows:

A:(1) My age is a multiple of six;

(2) My age is not the same asB‘s age;

(3)Dbelongs to a more truthful tribe than I do.

B:

(1) I am older thanA;

(2) The ages ofAandCare the same;

(3)D‘s age is a multiple of twelve.

C:

(1) I am older thanA;

(2)D‘s age is even;

(3)B‘s second remark is true.

D:

(1)Bis three times as old asC;

(2) My age is twelve more thanA‘s age;

(3)C‘s age is a multiple of thirteen.People tend to live for a long time on this wonderful island, but none of the four with whom this story deals is older than 105.

Find the tribes to which each man belongs, and their ages.

[puzzle26]

%d bloggers like this:

I think there is an issue with ages. For example if

XandYwere born on the same day, it is possible forXto say “I am older thanY“, and also forZto say “XandYare the same age”.Also if they were born a couple of days apart, on the day in between they would have different numerical ages, but

Zcould still reasonably say “XandYare the same age”.So here is my variation (taking the description of the tribes as read):

We can then proceed to solve this variation.

This Python program generates potential sets of numbers depending on who is telling the truth. It then examines the possible assignments of tribes, and chooses an appropriate set of numbers to consider. But it’s not quick, it runs in 16.7s (but there is a way to speed this up – see below).

Run:[ @repl.it ]Solution:A is a Shilla-Shalla, with 78 eggs; B is a Wotta-Woppa, with 78 eggs; C is a Shilla-Shalla, with 26 eggs; D is a Pukka, with 90 eggs.(Using ages, with the issue described above we can get multiple solutions. For example:

This would provide a viable solution if C born on the same day as A, but slightly earlier in the day).

We can do a bit of analysis to speed the program up:

We can see that

Ccannot be a Pukka (he says: (1) “C > A” and (3) “A = C”). AlsoAcannot be a Pukka (he says: (3) “D is more truthful than me”).If we remove these cases from consideration (see line 69) the run time is reduced to a more acceptable 772ms.

The program is written to use delayed evaluation provided by the [[

`Delay()`

]] class in theenigma.pylibrary (see my comment onEnigma 371), and it turns out that the [[`eggsA()`

]] function is never called (it generates over 11 million potential sets of numbers, so we save a lot of time by not generating and considering them).