Jump to content

Word wheel: Difference between revisions

1,381 bytes added ,  3 years ago
no edit summary
No edit summary
Line 1,784:
wok
woke</pre>
 
=={{header|Pascal}}==
{{works with|Free Pascal}}
<lang Pascal>
program WordWheel;
 
{$mode objfpc}{$H+}
 
uses
Classes, SysUtils;
 
const
WheelSize = 9;
MinLength = 3;
WordFile = 'unixdict.txt';
 
procedure search(pattern : string);
var
Allowed, Required, Available, w : string;
Len, i, p : integer;
WordList : TextFile;
Match : boolean;
begin
AssignFile(WordList, WordFile);
{$I-}
Reset(WordList);
{$I+}
if IOResult <> 0 then
begin
writeln('Could not open dictionary file ' + WordFile);
exit;
end;
Allowed := LowerCase(pattern);
Required := copy(Allowed, 5, 1);
while not eof(WordList) do
begin
readln(WordList, w);
Len := length(w);
Available := Allowed;
if (Len < MinLength) or (Len > WheelSize) then continue;
if pos(Required, w) = 0 then continue;
Match := True;
for i := 1 to Len do
begin
p := pos(w[i], Available);
if p > 0 then
{ prevent re-use of letter }
delete(Available, p, 1)
else
begin
Match := False;
break;
end;
end;
if Match then
writeln(w);
end;
end;
 
{ exercise the procedure }
begin
search('NDEOKGELW');
end.
</lang>
{{out}}
<pre>
eke
elk
keel
keen
keg
ken
keno
knee
kneel
knew
know
knowledge
kong
leek
week
wok
woke
</pre>
 
=={{header|Perl}}==
211

edits

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