Sunday Times Teaser 3190 – Mods-In-Suits
by Stephen Hogg
Sunday November 12 2023 (link)
In single-pack card game Mods-In-Suits, players are dealt two cards. Each card’s face value (Ace=1 to K=13) is modified by its suit, thus: “Spade” squares it; “Heart” halves it; “Club” changes its sign; “Diamond” divides it by the other card’s face value. Players score their modified values’ sum (or zero if there is a matching pair of face values). Players may exchange their second dealt card for a fresh card from the pack.
Stuck in the jam in the Smoke at rush hour, John’s children were missing Andy’s party. Playing Mods-In-Suits for amusement led to one unusual game. Jo’s initial score was a positive whole number, Bo’s its negative. Four different suits and face values were dealt. Both exchanged their second card, but each score was unchanged. Four different suits were still showing.
Give Jo’s final hand.
Brian, your code is very fast – much faster than mine: it usually is. But I think it can be made even faster by adding a test to line 24 to verify that the suits of the two cards are different:
Here is another approach.
A hybrid of Brian’s code and mine with an added twist: dictionary keys that are a tuple of hand score and the two suits of the hand. The values of the dictionaries are the 2 card values.