Brainteaser 1611: Scrambled egg
From The Sunday Times, 25th July 1993 [link]
When HUMPTY fell he broke into six pieces, each comprising one letter from his name, and they landed in a row to read as a rubbish six-letter word with none of the six piece in the correct position.
The King’s horses tried to put HUMPTY together again by arranging the pieces in the reverse order, which meant that more than one piece was in the right place.
The King’s men then split that arrangement into two threes and placed the last three pieces before the first. This gave a higher number of letters in the correct place.
What was the arrangement of letters just after HUMPTY fell?
This puzzle is included in the book Brainteasers (2002). The wording above is taken from the book. It is slightly changed from the original puzzle.
[teaser1611]
Jim Randell 9:07 am on 30 June 2019 Permalink |
This Python program tries all possible derangements of the letters, and checks to see if the conditions are satisfied. It runs in 85ms.
Run: [ @repl.it ]
from enigma import (subsets, join, printf) # word with letters in their correct positions word = "HUMPTY" # count the number of correct letters def correct(w): return sum(a == b for (a, b) in zip(w, word)) # find derangements of the word for w in subsets(word, size=len(word), select='P'): if correct(w) > 0: continue # reversing gives more than 1 piece in the correct position w1 = w[::-1] k1 = correct(w1) if not (k1 > 1): continue # putting the last 3 before the first 3 gives even more in the correct position w2 = w1[3:] + w1[:3] k2 = correct(w2) if not (k2 > k1): continue # output solution printf("{w} [{w1} -> {k1}, {w2} -> {k2}]", w=join(w), w1=join(w1), w2=join(w2))Solution: The arrangement after HUMPTY fell was MTHYUP.
LikeLike