Word wheel: Difference between revisions

no edit summary
m (→‎{{header|Haskell}}: Tidied, applied Ormolu.)
No edit summary
Line 1,762:
wok
woke</pre>
 
=={{header|q}}==
<lang q>ce:count each
lc:count each group@ / letter count
dict:system"curl http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"
// dictionary of 3-9 letter words
d39:{x where(ce x)within 3 9}{x where all each x in .Q.a}dict
 
solve:{[grid;dict]
i:where(grid 4)in'dict;
dict i where all each 0<=(lc grid)-/:lc each dict i }[;d39]</lang>
<lang q>q)`$solve "ndeokglew"
`eke`elk`keel`keen`keg`ken`keno`knee`kneel`knew`know`knowledge`kong`leek`week`wok`woke</lang>
A naive solution to the second question is simple
<lang q>bust:{[dict]
grids:distinct raze(til 9)rotate\:/:dict where(ce dict)=9;
wc:(count solve@)each grids;
grids where wc=max wc }</lang>
but inefficient. Better:
<lang q>best:{[dict]
dlc:lc each dict; / letter counts of dictionary words
ig:where(ce dict)=9; / find grids (9-letter words)
igw:where each(all'')0<=(dlc ig)-/:\:dlc; / find words composable from each grid (length ig)
grids:raze(til 9)rotate\:/:dict ig; / 9 permutations of each grid
iaz:(.Q.a)!where each .Q.a in'\:dict; / find words containing a, b, c etc
ml:4 rotate'dict ig; / mid letters for each grid
wc:ce raze igw inter/:'iaz ml; / word counts for grids
distinct grids where wc=max wc } / grids with most words</lang>
<lang q>q)show w:best d39
"ntclaremo"
"tspearmin"
 
q)ce solve each w
215 215</lang>
 
 
=={{header|Raku}}==
39

edits