Intro
This is for CentOS and RedHat Linux.
Narrow things down
$ egrep ′^[a-z]{6}$′ /usr/share/dict/linux.words |sed ′s/.//′|s
ort|uniq -c|sort -k1 -d -r > 6-ltr-last-5
Mind the line break in the display of this command – you have to join things back together.
This is a great string of commands to study if you want to unleash the power of the linux shell. Yuo have a matching operator, egrep, a simple regular expression, a substitution command, sed, a sort command, sort, a unique sort command, uniq, and a sort ordered by number and displayed in reverse order. I issue commands like this frequently against log files and can do much more import work than solving an NPR puzzle.
6-ltr-last-5 starts like this:
14 itter 14 ingle 14 atter 14 agged 13 etter 13 ester 13 aster 13 apper 13 apped 13 agger ... |
It has 772 lines with 4 or greater occurrences – too many to process by hand.
Edit this file and only keep the top part of the file up until the last of the 4 occurrences.
Now go back and match these words against the dictionary.
$ cat 6-ltr-last-5 |awk ′{print $2}′|while read line;do egrep ′
^[a-z]′$line$ /usr/share/dict/linux.words >> 6-ltr-combos;echo " ">>6-ltr-combos; done
6-ltr-combos starts like this:
bitter fitter gitter hitter jitter kitter litter nitter pitter ritter sitter titter witter zitter bingle cingle dingle gingle hingle jingle ... |
Small program to process that file
OK, to work with that file we just created based on the logic of the problem statement, I created this custom perl script which I call 6-5.pl:
#!/usr/bin/perl $DEBUG = 0; $consonants = 'bcdfghjlmnpqrstvwxyz'; $oldplace = -1; $pot = 0; while(<STDIN>){ if (/^\s/) { print "pot,start word = $pot, $startword\n" if $pot > 3; # reset some values $oldplace = -1; $pot = 0; $startword = $_; } chomp; # get at first character ($char) = /^(\w)/; # turn character into position number with this $place = index $consonants,$char; print "word,place: $_,$place\n" if $DEBUG; if ($place != $oldplace + 1) { # clear things out print "pot,start word = $pot, $startword\n" if $pot > 3; $pot = 1; $startword = $_; } else { $pot++; } print "pot: $pot\n" if $DEBUG; $oldplace = $place; } |
I really wish I knew Python – I bet it would be an even shorter script in that language. But this gets the job done. It’s warts and all as I have done enough debugging to get it to return mostly reasonable output, but it’s still not quite right. It’s good enough…
Run it:
$ ./6-5.pl < 6-ltr-combos
pot,start word = 4, fitter pot,start word = 7, gingle pot,start word = 4, latter pot,start word = 8, dagged pot,start word = 5, fetter pot,start word = 5, jester pot,start word = 6, dagger ... |
The biggest problem is my dictionary contains too many uncommon words, but at least that guarantees that the answer will indeed be present. And it is. In fact I found three sets of what I consider common words. One set are very ordinary words so i guess that is the intended answer. I can’t give away everything right now – you’ll have to do some work! I’ll post the answers after Sunday.
References and related
A similar approach to a previous puzzle is here.