Changeable words: Difference between revisions

no edit summary
(FutureBasic solution added)
No edit summary
 
(9 intermediate revisions by 6 users not shown)
Line 138:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
committeeperson <-> committeepeople
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
congressperson <-> congresspeople
councilpersoncouncilwoman <-> councilpeoplecouncilwomen
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
Line 162:
upperclassman <-> upperclassmen
</pre>
=={{header|ALGOL 68}}==
Brute force - tries each possible changed word.
<syntaxhighlight lang="algol68">
# find words where changing one letter results in another word #
# only words of 12 or more characters are to be considered #
IF FILE input file;
STRING file name = "unixdict.txt";
open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK #
BOOL at eof := FALSE;
# set the EOF handler for the file - notes eof has been reached and #
# returns TRUE so processing can continue #
on logical file end( input file, ( REF FILE f )BOOL: at eof := TRUE );
 
# table of possible words - there are around 1000 12+ character words #
[ 1 : 2 000 ]STRING words; # in unixdict.txt #
 
# in-place quick sort an array of strings #
PROC s quicksort = ( REF[]STRING a, INT lb, ub )VOID:
IF ub > lb
THEN
# more than one element, so must sort #
INT left := lb;
INT right := ub;
# choosing the middle element of the array as the pivot #
STRING pivot := a[ left + ( ( right + 1 ) - left ) OVER 2 ];
WHILE
WHILE IF left <= ub THEN a[ left ] < pivot ELSE FALSE FI
DO
left +:= 1
OD;
WHILE IF right >= lb THEN a[ right ] > pivot ELSE FALSE FI
DO
right -:= 1
OD;
left <= right
DO
STRING t := a[ left ];
a[ left ] := a[ right ];
a[ right ] := t;
left +:= 1;
right -:= 1
OD;
s quicksort( a, lb, right );
s quicksort( a, left, ub )
FI # s quicksort # ;
 
# returns the length of s #
OP LENGTH = ( STRING s )INT: 1 + ( UPB s - LWB s );
 
# returns TRUE if words[ low : high ] contains s, FALSE otherwise #
PROC is word = ( STRING s, INT low, high )BOOL:
IF high < low THEN FALSE
ELSE INT mid = ( low + high ) OVER 2;
IF words[ mid ] > s THEN is word( s, low, mid - 1 )
ELIF words[ mid ] = s THEN TRUE
ELSE is word( s, mid + 1, high )
FI
FI # is word # ;
 
INT w count := 0; # store the 12 character words #
WHILE
STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
IF LENGTH word > 11 THEN
words[ w count +:= 1 ] := word
FI
OD;
close( input file );
s quicksort( words, 1, w count ); # sort the words #
FOR i TO w count DO # find the changeable words #
STRING word = words[ i ];
STRING c word := word;
FOR i FROM LWB word TO UPB word DO
FOR c FROM ABS word[ i ] + 1 TO ABS "z" DO
c word[ i ] := REPR c;
IF is word( c word, 1, w count ) THEN
FOR p FROM LENGTH word TO 15 DO print( ( " " ) ) OD;
print( ( word, " <-> ", c word, newline ) )
FI
OD;
c word[ i ] := word[ i ]
OD
OD
FI
</syntaxhighlight>
{{out}}
<pre>
aristotelean <-> aristotelian
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
councilwoman <-> councilwomen
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
frontiersman <-> frontiersmen
handicraftsman <-> handicraftsmen
incommutable <-> incomputable
installation <-> instillation
kaleidescope <-> kaleidoscope
neuroanatomy <-> neuroanotomy
newspaperman <-> newspapermen
nonagenarian <-> nonogenarian
onomatopoeia <-> onomatopoeic
philanthrope <-> philanthropy
prescription <-> proscription
schizophrenia <-> schizophrenic
shakespearean <-> shakespearian
spectroscope <-> spectroscopy
underclassman <-> underclassmen
upperclassman <-> upperclassmen
</pre>
 
=={{header|Arturo}}==
 
Line 209 ⟶ 331:
underclassman - underclassmen
upperclassman - upperclassmen</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
Line 316 ⟶ 439:
committeeman committeemen
committeemen committeeman
committeewoman committeewomen
committeeperson committeepeople
committeewomen committeewoman
committeepeople committeeperson
complementary complimentary
complimentary complementary
confirmation conformation
conformation confirmation
congresswoman congresswomen
congressperson congresspeople
congresswomen congresswoman
congresspeople congressperson
councilwoman councilwomen
councilperson councilpeople
councilwomen councilwoman
councilpeople councilperson
craftsperson draftsperson
draftsperson craftsperson
Line 461 ⟶ 584:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 568 ⟶ 691:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 615 ⟶ 738:
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">
Line 670 ⟶ 913:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
committeeperson <-> committeepeople
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
congressperson <-> congresspeople
councilwoman <-> councilwomen
councilperson <-> councilpeople
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
Line 761 ⟶ 1,004:
committeeman ---> committeemen
committeemen ---> committeeman
committeepersoncommitteewoman ---> committeepeoplecommitteewomen
committeepeoplecommitteewomen ---> committeepersoncommitteewoman
complementary ---> complimentary
complimentary ---> complementary
confirmation ---> conformation
conformation ---> confirmation
congresspersoncongresswoman ---> congresspeoplecongresswomen
congresspeoplecongresswomen ---> congresspersoncongresswoman
councilpersoncouncilwoman ---> councilpeoplecouncilwomen
councilpeoplecouncilwomen ---> councilpersoncouncilwoman
craftsperson ---> draftsperson
draftsperson ---> craftsperson
Line 810 ⟶ 1,053:
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
#plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES}
 
include "NSLog.incl"
 
Line 974 ⟶ 1,220:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,105 ⟶ 1,351:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,224 ⟶ 1,470:
 
aristotelean <=> aristotelian claustrophobia <=> claustrophobic
committeeman <=> committeemen committeepersoncommitteewoman <=> committeepeoplecommitteewomen
complementary <=> complimentary confirmation <=> conformation
congresspersoncongresswoman <=> congresspeoplecongresswomen councilpersoncouncilwoman <=> councilpeoplecouncilwomen
craftsperson <=> draftsperson eavesdropped <=> eavesdropper
frontiersman <=> frontiersmen handicraftsman <=> handicraftsmen
Line 1,290 ⟶ 1,536:
 
Found 52 changeable words.</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
{$mode ObjFPC}{$H+}
uses
Classes, SysUtils;
 
const
FNAME = 'unixdict.txt';
 
function OneCharDifference(s1, s2: string): boolean;
var
i, diffCount: integer;
begin
diffCount := 0;
if Length(s1) <> Length(s2) then
Exit(false);
for i := 1 to Length(s1) do
begin
if s1[i] <> s2[i] then
Inc(diffCount);
if diffCount > 1 then
Exit(false);
end;
Result := diffCount = 1;
end;
 
procedure PurgeList(var list: TStringList);
{ Remove every word that doesn't have at least 12 characters }
var
i: Integer;
begin
for i := Pred(list.Count) downto 0 do
if Length(list[i]) < 12 then
list.Delete(i);
end;
 
var
list: TStringList;
i, j: Integer;
 
begin
list := TStringList.Create;
try
list.LoadFromFile(FNAME);
PurgeList(list);
for i := 0 to list.Count - 2 do
for j := i + 1 to list.Count - 1 do
if OneCharDifference(list[i], list[j]) then
writeln(list[i]:15, ' <-> ', list[j]);
finally
list.Free;
end;
end.
</syntaxhighlight>
{{out}}
<pre>
aristotelean <-> aristotelian
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
councilwoman <-> councilwomen
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
frontiersman <-> frontiersmen
handicraftsman <-> handicraftsmen
incommutable <-> incomputable
installation <-> instillation
kaleidescope <-> kaleidoscope
neuroanatomy <-> neuroanotomy
newspaperman <-> newspapermen
nonagenarian <-> nonogenarian
onomatopoeia <-> onomatopoeic
philanthrope <-> philanthropy
prescription <-> proscription
schizophrenia <-> schizophrenic
shakespearean <-> shakespearian
spectroscope <-> spectroscopy
underclassman <-> underclassmen
upperclassman <-> upperclassmen
</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
Line 1,313 ⟶ 1,645:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeepersoncommitteewoman <-> committeepeoplecommitteewomen
complementary <-> complimentary
confirmation <-> conformation
congresspersoncongresswoman <-> congresspeoplecongresswomen
councilpersoncouncilwoman <-> councilpeoplecouncilwomen
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
Line 1,336 ⟶ 1,668:
underclassman <-> underclassmen
upperclassman <-> upperclassmen
</pre> =={{header|Perl}}==Alternatively:
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
Line 1,469 ⟶ 1,801:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,571 ⟶ 1,903:
claustrophobia From claustrophobic
committeeman From committeemen
committeepersoncommitteewoman From committeepeoplecommitteewomen
complementary From complimentary
confirmation From conformation
congresspersoncongresswoman From congresspeoplecongresswomen
councilpersoncouncilwoman From councilpeoplecouncilwomen
craftsperson From draftsperson
eavesdropped From eavesdropper
Line 1,594 ⟶ 1,926:
underclassman From underclassmen
upperclassman From upperclassmen</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ over size
over size != iff
[ 2drop false ]
done
0 unrot
witheach
[ over i^ peek
!= rot + swap
over 2 = if
conclude ]
drop 1 = ] is 1diff ( $ $ --> b )
 
$ "rosetta/unixdict.txt"
sharefile drop nest$
[] swap witheach
[ dup size 11 > iff
[ nested join ]
else drop ]
[ behead over witheach
[ 2dup
1diff iff
[ over echo$
sp echo$ cr ]
else drop ]
drop
dup size 1 = until ]
drop</syntaxhighlight>
 
{{out}}
 
<pre>aristotelean aristotelian
claustrophobia claustrophobic
committeeman committeemen
committeewoman committeewomen
complementary complimentary
confirmation conformation
congresswoman congresswomen
councilwoman councilwomen
craftsperson draftsperson
eavesdropped eavesdropper
frontiersman frontiersmen
handicraftsman handicraftsmen
incommutable incomputable
installation instillation
kaleidescope kaleidoscope
neuroanatomy neuroanotomy
newspaperman newspapermen
nonagenarian nonogenarian
onomatopoeia onomatopoeic
philanthrope philanthropy
prescription proscription
schizophrenia schizophrenic
shakespearean shakespearian
spectroscope spectroscopy
underclassman underclassmen
upperclassman upperclassmen</pre>
 
=={{header|Raku}}==
Sorensen-Dice is very fast to calculate similarities but isn't great for detecting small changes. Levenshtein is great for detecting small changes but isn't very fast.
Line 1,621 ⟶ 2,013:
2: claustrophobia <-> claustrophobic
3: committeeman <-> committeemen
4: committeepersoncommitteewoman <-> committeepeoplecommitteewomen
5: complimentary <-> complementary
6: confirmation <-> conformation
7: congresspersoncongresswoman <-> congresspeoplecongresswomen
8: councilpersoncouncilwoman <-> councilpeoplecouncilwomen
9: draftsperson <-> craftsperson
10: eavesdropped <-> eavesdropper
Line 1,695 ⟶ 2,087:
committeeman committeemen
committeemen committeeman
committeepersoncommitteewoman committeepeoplecommitteewomen
committeepeoplecommitteewomen committeepersoncommitteewoman
complementary complimentary
complimentary complementary
confirmation conformation
conformation confirmation
congresspersoncongresswoman congresspeoplecongresswomen
congresspeoplecongresswomen congresspersoncongresswoman
councilpersoncouncilwoman councilpeoplecouncilwomen
councilpeoplecouncilwomen councilpersoncouncilwoman
craftsperson draftsperson
draftsperson craftsperson
Line 1,791 ⟶ 2,183:
5. committeeman >> committeemen
6. committeemen >> committeeman
7. committeewoman >> committeewomen
7. committeeperson >> committeepeople
8. committeewomen >> committeewoman
8. committeepeople >> committeeperson
9. complementary >> complimentary
10. complimentary >> complementary
11. confirmation >> conformation
12. conformation >> confirmation
13. congresspersoncongresswoman >> congresspeoplecongresswomen
14. congresspeoplecongresswomen >> congresspersoncongresswoman
15. councilpersoncouncilwoman >> councilpeoplecouncilwomen
16. councilpeoplecouncilwomen >> councilpersoncouncilwoman
17. craftsperson >> draftsperson
18. draftsperson >> craftsperson
Line 1,942 ⟶ 2,334:
{{libheader|Wren-fmt}}
Using the Hamming Distance between two equal length strings which needs to be 1 here:
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./fmt" for Fmt
 
var hammingDist = Fn.new { |s1, s2|
Line 1,984 ⟶ 2,376:
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeepersoncommitteewoman -> committeepeoplecommitteewomen
8: committeepeoplecommitteewomen -> committeepersoncommitteewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresspersoncongresswoman -> congresspeoplecongresswomen
14: congresspeoplecongresswomen -> congresspersoncongresswoman
15: councilpersoncouncilwoman -> councilpeoplecouncilwomen
16: councilpeoplecouncilwomen -> councilpersoncouncilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 2,031 ⟶ 2,423:
52: upperclassmen -> upperclassman
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0; \use zero-terminated strings
Line 2,115 ⟶ 2,508:
5 committeeman committeemen
6 committeemen committeeman
7 committeepersoncommitteewoman committeepeoplecommitteewomen
8 committeepeoplecommitteewomen committeepersoncommitteewoman
9 complementary complimentary
10 complimentary complementary
11 confirmation conformation
12 conformation confirmation
13 congresspersoncongresswoman congresspeoplecongresswomen
14 congresspeoplecongresswomen congresspersoncongresswoman
15 councilpersoncouncilwoman councilpeoplecouncilwomen
16 councilpeoplecouncilwomen councilpersoncouncilwoman
17 craftsperson draftsperson
18 draftsperson craftsperson
45

edits