Word wheel: Difference between revisions
Content deleted Content added
→{{header|REXX}}: added a language stub for REXX. |
→{{header|REXX}}: added a computer programming example for REXX. |
||
Line 347: | Line 347: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm finds (dictionary) words which can be found in a specified word wheel (grid).*/ |
|||
<lang rexx></lang rexx> |
|||
parse arg grid mLen iFID . /*obtain optional arguments from the CL*/ |
|||
if grid==''|grid=="," then grid= 'ndeokgelw' /*Not specified? Then use the default.*/ |
|||
if mLen==''|mLen=="," then mLen= 3 /* " " " " " " */ |
|||
if iFID==''|iFID=="," then iFID= 'UNIXDICT.TXT' /* " " " " " " */ |
|||
gridU= grid; upper gridU; guAir= inflate(gridU) /*get an uppercase version of the grid.*/ |
|||
Lg= length(grid); Hg= Lg%2 |
|||
c= substr(grid, Hg+1,1 ); upper c /*get uppercase center letter in grid. */ |
|||
wrds= 0 /*# words that are in the dictionary. */ |
|||
wees= 0 /*" " " " too short. */ |
|||
dups= 0 /*" " " " duplicates. */ |
|||
ills= 0 /*" " " contain not letters.*/ |
|||
good= 0 /*" " " contain center letter. */ |
|||
say ' Reading the file: ' iFid |
|||
@.= . /*uppercase non─duplicated dict. words.*/ |
|||
$= /*the list of dictionary words in grid.*/ |
|||
do recs=1 while lines(ifid)\==0 /*process all words in the dictionary. */ |
|||
_= linein(iFID) /*read a word (line of text) from dict.*/ |
|||
u= space(_, 0); upper u; L= length(u) /*elide superfluous blanks from a word.*/ |
|||
L= length(u) /*obtain the length of the word. */ |
|||
if @.u\==. then do; dups= dups+1; iterate; end /*is this a duplicate? */ |
|||
if \datatype(u,'U') then do; ills= ills+1; iterate; end /*has word non─letters? */ |
|||
@.u= /*signify that U is a dictionary word*/ |
|||
wrds= wrds + 1 /*bump the number of "good" dist. words*/ |
|||
if pos(c, u)==0 then iterate /*word doesn't have center grid letter.*/ |
|||
good= good + 1 /*bump # center─letter words in dict. */ |
|||
if verify(u, gridU)\==0 then iterate /*word contains a letter not in grid. */ |
|||
air= inflate(u) /*insert "air" (blanks) between letters*/ |
|||
if \deflate(air, guAir) then iterate /*have all the letters been found ? */ |
|||
$= $ u /*add this word to the "found" list. */ |
|||
end /*recs*/ |
|||
say |
|||
say 'number of records (lines) in the dictionary: ' right( commas(recs), 9) |
|||
say 'number of ill─formed words in the dictionary: ' right( commas(ills), 9) |
|||
say 'number of duplicate words in the dictionary: ' right( commas(dups), 9) |
|||
say 'number of too─small words in the dictionary: ' right( commas(wees), 9) |
|||
say 'number of acceptable words in the dictionary: ' right( commas(wrds), 9) |
|||
say 'number center─letter words in the dictionary: ' right( commas(good), 9) |
|||
say ' the word wheel being used: ' lower(grid) |
|||
say ' the center of the word wheel being used: ' right('↑', Hg+1) |
|||
say |
|||
say 'number of word wheel words in the dictionary: ' right( commas(words($) ), 9) |
|||
say |
|||
say 'The list of word wheel words found:'; say |
|||
say lower( strip($) ) |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
lower: arg aa; @='abcdefghijklmnopqrstuvwxyz'; @u=@; upper @u; return translate(aa,@,@U) |
|||
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _ |
|||
inflate: procedure; arg z 1 a 2; do m=2 to length(z); a= a substr(z,m,1); end; return a |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
deflate: procedure; arg aa,guA; Laa= length(aa) |
|||
do n=1 to Laa by 2; p= wordpos( substr(aa,n,1), guA); if p==0 then return 0 |
|||
guA= delword(guA, p, 1) |
|||
end /*n*/; return 1</lang> |
|||
{{out|output|text= when using the default inputs:}} |
|||
<pre> |
|||
Reading the file: UNIXDICT.TXT |
|||
number of records (lines) in the dictionary: 25,105 |
|||
number of ill─formed words in the dictionary: 126 |
|||
number of duplicate words in the dictionary: 0 |
|||
number of too─small words in the dictionary: 0 |
|||
number of acceptable words in the dictionary: 24,978 |
|||
number center─letter words in the dictionary: 1,841 |
|||
the word wheel being used: ndeokgelw |
|||
the center of the word wheel being used: ↑ |
|||
number of word wheel words in the dictionary: 19 |
|||
The list of word wheel words found: |
|||
eke elk k keel keen keg ken keno knee kneel knew know knowledge kong leek ok week wok woke |
|||
</pre> |