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.

Enigma 119


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
    for votes in product(parties, repeat=3):
      # 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
      (T, D, H) = votes
      printf("T={T} D={D} H={H} w={w} m={m}")

    Solution: Tom voted Labour; Dick voted Liberal; Harry voted Labour.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: