Jumble
March 1, 2019
Last week I gave a rather silly solution to the Scrabble problem. Today’s exercise is my penance for that silliness.
As I’ve mentioned previously, my day job is on a team of programmers that supports our enterprise-wide computer system. I sit in a cube farm, where there is neither audible nor visual privacy. We recently hired a new programmer to replace a retiring team member, and he has a daily calendar on his desk that provides a jumbled series of letters that you have to rearrange to form a word. Yesterday’s puzzle was L T E A D E
; most of the puzzles I solve in a few seconds, but that one took several minutes. The calendar appears to have a flaw: the solutions, one day after the next, are in alphabetical order, so I know before I start that the first letter will be E
.
Your task is to write a program that solves jumbles. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
I was really happy to get this one right…. although I came up with an archaic one as there is also a solution starting with “d”…
delate (verb)
Quick one in Ruby.
Outputs
A Haskell version.
Has an option to specify what the word starts with.
Here’s a solution in Python.
Output:
Solution with gawk, posix awk doesn’t have asort, BYO to make it more portable.
#! /usr/bin/gawk -f
jumble - solves a jumbled word puzzle
usage: jumble [-v puzzle="XXX"] [path/to/dictionary]
BEGIN {
IGNORECASE = 1
if( puzzle == "" ) puzzle = "LTEADE"
split(puzzle, puzzle_arr, "")
puzzle_len = asort(puzzle_arr)
}
{
if( length($0) != puzzle_len ) next
split($0, test_arr, "")
asort(test_arr)
for( i = 1 ; i <= puzzle_len ; i++ )
if( test_arr[i] != puzzle_arr[i] ) next
print FILENAME ": " $0
}
In action:
./jumble.awk -v puzzle="LTEADE" /usr/share/dict/*
/usr/share/dict/american-english: elated
/usr/share/dict/british: elated
/usr/share/dict/british-english: elated
/usr/share/dict/catala: delate
/usr/share/dict/catalan: delate
/usr/share/dict/german: adelte
/usr/share/dict/german: dealte
/usr/share/dict/german: tadele
/usr/share/dict/ngerman: adelte
/usr/share/dict/ngerman: dealte
/usr/share/dict/ngerman: tadele
/usr/share/dict/usa: elated
/usr/share/dict/words: elated
[…] exercise was posted over at ProgrammingPraxis called […]
Klong version (#5)
lteade:
elated
dbeia:
abide
groegj:
jogger
slenet:
nestle
nargo:
argon
groan
organ
“** Done **”