Debian Codegraph @

cw-solver.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # cw-solver.sh
3 # This is actually a wrapper around a one-liner (line 46).
4
5 # Crossword puzzle and anagramming word game solver.
6 # You know *some* of the letters in the word you're looking for,
7 #+ so you need a list of all valid words
8 #+ with the known letters in given positions.
9 # For example: w...i....n
10 # 1???5????10
11 # w in position 1, 3 unknowns, i in the 5th, 4 unknowns, n at the end.
12 # (See comments at end of script.)
13
14
15 E_NOPATT=71
16 DICT=/usr/share/dict/word.lstscip-shell filesystem . . `/usr/share/dict/word.lst`.
17 # ^^^^^^^^ Looks for word list here.
18 # ASCII word list, one word per line.
19 # If you happen to need an appropriate list,
20 #+ download the author's "yawl" word list package.
21 # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz
22 # or
23 # http://bash.deta.in/yawl-0.3.2.tar.gz
24
25
26 if [scip-shell system . . `[`. -z "$1" ] # If no word pattern specified
27 then #+ as a command-line argument . . .
28 echoscip-shell system . . echo. #+ . . . then . . .
29 echoscip-shell system . . echo. "Usage:" #+ Usage message.
30 echoscip-shell system . . echo.
31 echoscip-shell system . . echo. ""$0" \"pattern,\""
32 echoscip-shell system . . echo. "where \"pattern\" is in the form"
33 echoscip-shell system . . echo. "xxx..x.x..."
34 echoscip-shell system . . echo.
35 echoscip-shell system . . echo. "The x's represent known letters,"
36 echoscip-shell system . . echo. "and the periods are unknown letters (blanks)."
37 echoscip-shell system . . echo. "Letters and periods can be in any position."
38 echoscip-shell system . . echo. "For example, try: sh cw-solver.sh w...i....n"
39 echoscip-shell system . . echo.
40 exit $E_NOPATT
41 fi
42
43 echoscip-shell system . . echo.
44 # ===============================================
45 # This is where all the work gets done.
46 grepscip-shell system . . grep. ^"$1"$ "$DICT" # Yes, only one line!
47 # | |
48 # ^ is start-of-word regex anchor.
49 # $ is end-of-word regex anchor.
50
51 # From _Stupid Grep Tricks_, vol. 1,
52 #+ a book the ABS Guide author may yet get around
53 #+ to writing . . . one of these days . . .
54 # ===============================================
55 echoscip-shell system . . echo.
56
57
58 exit $? # Script terminates here.
59 # If there are too many words generated,
60 #+ redirect the output to a file.
61
62 $ sh cw-solver.sh w...i....n
63
64 wellington
65 workingman
66 workingmen