Jump to content

Word wheel: Difference between revisions

1,532 bytes added ,  3 years ago
Add BCPL
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Add BCPL)
Line 690:
letters: kndeogelw, 'k' required, 17 words >= 3 characters
</pre>
 
=={{header|BCPL}}==
<lang bcpl>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()
$)</lang>
{{out}}
<pre>eke
elk
keel
keen
keg
ken
keno
knee
kneel
knew
know
knowledge
kong
leek
week
wok
woke</pre>
 
=={{header|C}}==
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.