Find out the words, just for fun

There is a spell game to find out the word which can be used between another two words, for example,

play   ______    table
hair    ______    ball

So missing word will be:

time  (playtime, timetable)
pin  (hairpin, pinball)

time and pin are also real word. Maybe there are not only one answer.

So my idea is, maybe we use dictionary files to do the game.

/usr/dict/words
or
/usr/share/dict/words

I am working on it, if you have any idea, please paste here.

the script should be run be this way:

spell_game play table

get the answer such as:

playtime, timetable

just a start....

$ cat spell_game
#!/bin/bash

matches=`awk '
(/^ball/ || /ball$/) && !(/^ball$/||/s$/||/ing$/||/ed$/||/er$/) {
  gsub(/ball/,"")
  if(length($0)>1) {print $0}
  $0=""
}

(/^hair/ || /hair$/) && !(/^hair$/||/s$/||/ing$/||/ed$/||/er$/) {
  gsub(/hair/,"")
  if(length($0)>1) {print $0}
  $0=""
}' /usr/share/dict/words | sort -d | uniq -d`

matchcnt=`echo "$matches" | wc -l | awk '{print $1}'`

if [ ${matchcnt} -eq 0 ]; then
  echo "Sorry, I can't solve this one."
  exit 2
fi

if [ ${matchcnt} -eq 1 ]; then
  echo There was "${matchcnt}" possibility: "${matches}"
else
  echo There were "${matchcnt}" possibilities: "${matches}"
  exit 0
fi

Done.

$ cat spell_game
#!/usr/bin/bash

WORD="/usr/dict/words"

for i in `grep "^$1." $WORD`
do
   KEY="${i#$1}"
   NEW="${i#$1}$2"
   grep "^$NEW$" $WORD > /dev/null && echo "$i, $NEW"
done
$ ./spell_game play table
playtime, timetable
$ ./spell_game hair ball
hairpin, pinball
$ ./spell_game high lay
highway, waylay

man, why must I always do things in the strangest of ways....

Mate, that's fine. That's the reason we come here to share and learn each other.

something like below, but i am concerning on the performance.:stuck_out_tongue:

for i in `egrep '^play.*' /usr/dict/words | sed 's/^play//' `;do
egrep "^${i}table$" /usr/dict/words > /dev/null
if [ $? -eq 0 ];then
echo $i
fi
done

Yes, get the answer.

You are perl guru, do it by perl? :wink:

I'd like to use $1 and $2 as input to get different pair of words. such as, if you run:

spell_game.pl fire day

what result can you get?

A very good game ... Is there any list of similar words for computer words.
Like programing languages: A Ada, B, Brain..., C, C++ ... etc etc ..