52 lines
1.3 KiB
Text
52 lines
1.3 KiB
Text
get "libhdr"
|
|
|
|
// Read word from selected input
|
|
let readword(v) = valof
|
|
$( let ch = ?
|
|
v%0 := 0
|
|
$( ch := rdch()
|
|
if ch = endstreamch then resultis false
|
|
if ch = '*N' then resultis true
|
|
v%0 := v%0 + 1
|
|
v%(v%0) := ch
|
|
$) repeat
|
|
$)
|
|
|
|
// Test word against wheel
|
|
let match(wheel, word) = valof
|
|
$( let wcopy = vec 2+9/BYTESPERWORD
|
|
for i = 0 to wheel%0 do wcopy%i := wheel%i
|
|
for i = 1 to word%0 do
|
|
$( let idx = ?
|
|
test valof
|
|
$( for j = 1 to wcopy%0 do
|
|
if word%i = wcopy%j then
|
|
$( idx := j
|
|
resultis true
|
|
$)
|
|
resultis false
|
|
$) then wcopy%idx := 0 // we've used this letter
|
|
else resultis false // word cannot be made
|
|
$)
|
|
resultis
|
|
wcopy%((wcopy%0+1)/2)=0 & // middle letter must be used
|
|
3 <= valof // at least 3 letters must be used
|
|
$( let count = 0
|
|
for i = 1 to wcopy%0 do
|
|
if wcopy%i=0 then count := count + 1
|
|
resultis count
|
|
$)
|
|
$)
|
|
|
|
// Test unixdict.txt against ndeokgelw
|
|
let start() be
|
|
$( let word = vec 2+64/BYTESPERWORD
|
|
let file = findinput("unixdict.txt")
|
|
let wheel = "ndeokgelw"
|
|
|
|
selectinput(file)
|
|
while readword(word) do
|
|
if match(wheel, word) do
|
|
writef("%S*N", word)
|
|
endread()
|
|
$)
|