# Enigmatic Code

Programming Enigma Puzzles

## Enigma 169: A matter of honours

From New Scientist #1314, 15th July 1982 [link]

In last night’s final hand at Bridge, each player found himself dealt four honours cards, no two of them in the same suit. Counting 4 for an ace, 3 for a king, 2 for a queen and 1 for a jack, each had a different number of points. No one had a pair of red aces or a pair of black kings. Someone held the king of hearts and his partner the queen. Someone held the king of clubs and his partner the queen. Someone held the king of spades and his partner did not hold the queen.

North’s spade was lower than his heart and his diamond was lower than his club. West had more jacks than North, who had more jacks than East. If East did not have the queen of clubs, then South had the ace of hearts. If North did not have the queen of spades then West had the king of spades.

Can you work out which four honours each of them held?

[enigma169]

### One response to “Enigma 169: A matter of honours”

1. Jim Randell 15 February 2014 at 9:44 am

This Python program runs in 61ms.

```from itertools import permutations
from enigma import printf

# each player holds a card of each suit. we need to assign A, K, Q, J
# in some order to each column, such that the conditions hold.
#
#    H D S C
#  N . . . .
#  E . . . .
#  S . . . .
#  W . . . .

# assign some constants (note: S = South _and_ Spades)
(A, K, Q, J) = (4, 3, 2, 1)
(H, D, S, C) = (0, 1, 2, 3)
(N, E, W) = (0, 1, 3)

# choose the order for Hearts
for h in permutations((A, K, Q, J)):
# KH and QH are with partners
if h.index(K) % 2 != h.index(Q) % 2: continue

# choose the order for Spades
for s in permutations((A, K, Q, J)):
# KS and QS are not with partners
if s.index(K) % 2 == s.index(Q) % 2: continue
# N's spade is lower than his heart
if not(s[N] < h[N]): continue

# choose the order for Clubs
for c in permutations((A, K, Q, J)):
# KC and QC are with partners
if c.index(K) % 2 != c.index(Q) % 2: continue

# choose the order for Diamonds
for d in permutations((A, K, Q, J)):
# N's diamond is lower than his club
if not(d[N] < c[N]): continue

# generate the hands
hand = list((h[i], d[i], s[i], c[i]) for i in (N, E, S, W))

# each person has a different number of points
if len(set(sum(p) for p in hand)) < 4: continue

# no-one has a pair of red aces, or a pair of black kings
if any(h == d == A or s == c == K for (h, d, s, c) in hand): continue

# W has more jacks than N, N has more jacks than E
if not(hand[W].count(J) > hand[N].count(J) > hand[E].count(J)): continue

# if E does not have QC then S has AH
if hand[E][C] != Q and hand[S][H] != A: continue

# if N does not have QS then W has KS
if hand[N][S] != Q and hand[W][S] != K: continue

# output the hands
for (h, n) in zip(hand, 'NESW'):
printf("{n}: {h}", h=' '.join('?JQKA'[p] + s for (p, s) in zip(h, 'HDSC')))
printf('')
```

Solution: The hands are: