# Enigmatic Code

Programming Enigma Puzzles

## Enigma 119: Floating voters

From New Scientist #1263, 23rd July 1981 [link]

Tom, Dick and Harry are typical floating voters and their friends ran a book on how they would vote at the council elections. For 10p you could have one shot at predicting all three. The pay-off was £1 for three right, 40p for two and a consolation 20p for being right about Tom only (he being especially inscrutable).

My wife and I decided each to have six shots and both did quite well. In fact she made 60p profit on her six and I made 40p profit on mine. Our guesses are listed below and we invite you to say how Tom, Dick and Harry actually voted.

[enigma119]

### One response to “Enigma 119: Floating voters”

1. Jim Randell 20 August 2013 at 7:53 am

It’s very straightforward just to check all 27 possibilities. This Python program runs in 33ms.

```from itertools import product
from enigma import printf

# save on quotes
(Con, Lab, Lib) = parties = ('Con', 'Lab', 'Lib')

Hers = (
(Lab, Lib, Lab),
(Lib, Lib, Con),
(Con, Lab, Lib),
(Lib, Lab, Con),
(Lab, Con, Lib),
(Con, Con, Lab)
)

Mine = (
(Lab, Lib, Lib),
(Lib, Lab, Lab),
(Con, Lab, Lab),
(Lab, Lab, Con),
(Con, Con, Lib),
(Lab, Con, Lab)
)

def winnings(actual, guess):
right = list(n for (n, a, g) in zip('TDH', actual, guess) if a == g)
if len(right) == 3: return 100
if len(right) == 2: return 40
if 'T' in right: return 20
return 0

# profit for the wife
w = sum(winnings(votes, x) - 10 for x in Hers)
if w != 60: continue
# profit for the setter
m = sum(winnings(votes, x) - 10 for x in Mine)
if m != 40: continue