Changeable words: Difference between revisions

no edit summary
(FutureBasic solution added)
No edit summary
Line 615:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Classes,SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
var Dict: TStringList; {List holds dictionary}
 
 
procedure DoChangeWords(Memo: TMemo);
{Do change word problem}
var I,J,K,Inx,Cnt: integer;
var S: string;
 
procedure Display(OldStr,NewStr: string);
{Display both the original word and the modified word}
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+': '+OldStr+' '+NewStr);
end;
 
begin
Cnt:=0;
{Check every word in the dictionary}
for I:=0 to Dict.Count-1 do
begin
{Only check words at least 12 chars long}
if Length(Dict[I])>=12 then
begin
{Test a specific position in the word}
for J:=1 to Length(Dict[I]) do
begin
{try all combinations of alpha chars in the position}
for K:=byte('a') to byte('z') do
begin
{skip if the char is already in the position}
if Dict[I][J]=char(K) then continue;
{Get a new copy of the word to modify}
S:=Dict[I];
{Modify the position}
S[J]:=char(K);
{Is it in the dictionary? }
Inx:=Dict.IndexOf(S);
{Display it if it is}
if Inx>=0 then Display(Dict[I],S);
end;
end;
end;
end;
end;
 
 
initialization
{Create/load dictionary}
Dict:=TStringList.Create;
Dict.LoadFromFile('unixdict.txt');
Dict.Sorted:=True;
finalization
Dict.Free;
end.
</syntaxhighlight>
{{out}}
<pre>
 
1: aristotelean aristotelian
2: aristotelian aristotelean
3: claustrophobia claustrophobic
4: claustrophobic claustrophobia
5: committeeman committeemen
6: committeemen committeeman
7: committeewoman committeewomen
8: committeewomen committeewoman
9: complementary complimentary
10: complimentary complementary
11: confirmation conformation
12: conformation confirmation
13: congresswoman congresswomen
14: congresswomen congresswoman
15: councilwoman councilwomen
16: councilwomen councilwoman
17: craftsperson draftsperson
18: draftsperson craftsperson
19: eavesdropped eavesdropper
20: eavesdropper eavesdropped
21: frontiersman frontiersmen
22: frontiersmen frontiersman
23: handicraftsman handicraftsmen
24: handicraftsmen handicraftsman
25: incommutable incomputable
26: incomputable incommutable
27: installation instillation
28: instillation installation
29: kaleidescope kaleidoscope
30: kaleidoscope kaleidescope
31: neuroanatomy neuroanotomy
32: neuroanotomy neuroanatomy
33: newspaperman newspapermen
34: newspapermen newspaperman
35: nonagenarian nonogenarian
36: nonogenarian nonagenarian
37: onomatopoeia onomatopoeic
38: onomatopoeic onomatopoeia
39: philanthrope philanthropy
40: philanthropy philanthrope
41: prescription proscription
42: proscription prescription
43: schizophrenia schizophrenic
44: schizophrenic schizophrenia
45: shakespearean shakespearian
46: shakespearian shakespearean
47: spectroscope spectroscopy
48: spectroscopy spectroscope
49: underclassman underclassmen
50: underclassmen underclassman
51: upperclassman upperclassmen
52: upperclassmen upperclassman
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
465

edits