Saturday, November 10, 2012

Word games

So The Age publishes a word game - Target - in the weekend paper. The rules are simple: you get 9 letters, and have to make as many words of 4 letters or more out of them, and there is one of the letters which must be included in all words. You also have to figure out what the original 9-letter word was which got scrambled up to provide the 9 letters. I quite like the challenge of making words out of the letters, but I rarely figure out the 9-letter word. It frustrates me. In fact, so much that I seem to spend more time figuring out ways to write a program to solve it for me. Yeah, really.

Anyway, I couldn't be bothered doing it "properly" so I decided to do a quick command-line hack to solve it. Today's quiz had the letters H K I A R T B R M Witness the following ugliness:



grep  '^.........$' /usr/share/dict/words|grep 'k'|grep 'r'|grep 'm'| grep 'h' |grep -E '[i]{1}'|grep -E '[a]+'|grep -v '[eou]'

There must be more elegant ways to achieve this, but still, it got the job done in a couple of minutes.

Oh, and the word was "birthmark" in case you wondered :-)

Edit: I solved this properly in perl today.

4 comments:

  1. Maybe
    $ grep "^[hkkrmhiaiartbrm]$" /usr/share/dict/words

    ?

    ReplyDelete
    Replies
    1. Bloody keyboard
      I meant

      $ grep "^[hkiartbrm]$" /usr/share/dict/words

      Delete
  2. Sloppy... last try
    I meant....

    grep "^[hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm][hkiartbrm]$" /usr/share/dict/words

    ReplyDelete