### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,609)
- enigma-book-1982 (70)
- misc (5)
- project euler (2)
- puzzle (90)
- puzzle# (173)
- site news (76)
- tantalizer (189)
- teaser (7)
- today (1)

### Site Stats

- 310,314 hits

Programming Enigma Puzzles

6 June 2022

Posted by on **From New Scientist #1817, 18th April 1992** [link]

As you can see from my friend’s latest letter, there’s been a general election in Utopia too:

“You will recall that the state of the four parties after the 1989 election was Sinistrals 289, Dextrous 243, Others 36, Indeterminates 32. This remained the case right up to the breakup of the ruling coalition last month, when new elections to the Scitting were held. This time the following occurred:

1. The Sinistrals finished with more seats, the other three parties with less.

2. The Sinistrals lost an equal number of seats to each of the other three parties and gained some seats.

3. The Dextrous and Indeterminate parties both won seats from the Sinistrals only.

4. The relative positions of the parties are unchanged.

5. Each party gained

andlost either a perfect square or a perfect cube of seats to finish with either a perfect square or perfect cube number of seats.6. The total number of seats is unchanged and no other party won a seat.

So now you can work out the new state of the parties.”

Can you?

[enigma662]

%d bloggers like this:

We can think of this puzzle as filling out a 4×4 table, where entry

(X, Y)corresponds to the number of voters who voted forXin the first election andYin the second election.The column sums then give us the total for each party in the first election (which we are given), and the row sums give us the total for each party in the second election (which we want to find out). The results of the second election are all squares/cubes.

We are also told that each of the gains/losses for each party are also a square/cube. Which means the row/column sums, excluding the value that falls on a diagonal are all square/cubes.

This Python program fills out the table, to give the results in the second election.

It runs in 67ms. (Internal run time is 3.61ms).

Run:[ @replit ]Solution:The results in the second election are: Sinistrals = 343; Dextrous = 216; Others = 25; Indeterminate = 16.There are 25 possible tables that correspond to this scenario. Here is one of them:

@Jim, my python-constraint program prints 26 solutions.

Is the following solution incorrect?

@Frits: The values you give don’t work as a solution.

Each of the gains/losses for each party must be a square/cube. And in that example the losses for O (i.e. the number of voters who voted for O in the first election and a party other than O in the second) come to 20. Which is neither a square nor a cube.

@Jim, Thanks, I had difficulties reading the matrix (I didn’t read your explanation)

Hi Jim, I finally noticed that the current number of votes for Dextrous should be 243 (in the question), as in your program. It makeslife easier.

Tony Mcardle

@Tony: Sorry about that. I’ve corrected the puzzle text.

Some constraints have been coded as domains.

The program runs in 50ms.