Changeable words: Difference between revisions
no edit summary
(Added Quackery.) |
No edit summary |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 138:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
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
committeewomen committeewoman
complementary complimentary
complimentary complementary
confirmation conformation
conformation confirmation
congresswoman congresswomen
congresswomen congresswoman
councilwoman councilwomen
councilwomen councilwoman
craftsperson draftsperson
draftsperson craftsperson
Line 461 ⟶ 584:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 568 ⟶ 691:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 790 ⟶ 913:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
committeewoman <-> committeewomen
complementary <-> complimentary
confirmation <-> conformation
congresswoman <-> congresswomen
councilwoman <-> councilwomen
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
Line 881 ⟶ 1,004:
committeeman ---> committeemen
committeemen ---> committeeman
complementary ---> complimentary
complimentary ---> complementary
confirmation ---> conformation
conformation ---> confirmation
craftsperson ---> draftsperson
draftsperson ---> craftsperson
Line 1,097 ⟶ 1,220:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,228 ⟶ 1,351:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,347 ⟶ 1,470:
aristotelean <=> aristotelian claustrophobia <=> claustrophobic
committeeman <=> committeemen
complementary <=> complimentary confirmation <=> conformation
craftsperson <=> draftsperson eavesdropped <=> eavesdropper
frontiersman <=> frontiersmen handicraftsman <=> handicraftsmen
Line 1,413 ⟶ 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,436 ⟶ 1,645:
claustrophobia <-> claustrophobic
committeeman <-> committeemen
complementary <-> complimentary
confirmation <-> conformation
craftsperson <-> draftsperson
eavesdropped <-> eavesdropper
Line 1,459 ⟶ 1,668:
underclassman <-> underclassmen
upperclassman <-> upperclassmen
</pre>
<syntaxhighlight lang="perl">#!/usr/bin/perl
Line 1,592 ⟶ 1,801:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 1,694 ⟶ 1,903:
claustrophobia From claustrophobic
committeeman From committeemen
complementary From complimentary
confirmation From conformation
craftsperson From draftsperson
eavesdropped From eavesdropper
Line 1,804 ⟶ 2,013:
2: claustrophobia <-> claustrophobic
3: committeeman <-> committeemen
4:
5: complimentary <-> complementary
6: confirmation <-> conformation
7:
8:
9: draftsperson <-> craftsperson
10: eavesdropped <-> eavesdropper
Line 1,878 ⟶ 2,087:
committeeman committeemen
committeemen committeeman
complementary complimentary
complimentary complementary
confirmation conformation
conformation confirmation
craftsperson draftsperson
draftsperson craftsperson
Line 1,974 ⟶ 2,183:
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.
14.
15.
16.
17. craftsperson >> draftsperson
18. draftsperson >> craftsperson
Line 2,125 ⟶ 2,334:
{{libheader|Wren-fmt}}
Using the Hamming Distance between two equal length strings which needs to be 1 here:
<syntaxhighlight lang="
import "./fmt" for Fmt
var hammingDist = Fn.new { |s1, s2|
Line 2,167 ⟶ 2,376:
5: committeeman -> committeemen
6: committeemen -> committeeman
7:
8:
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13:
14:
15:
16:
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
Line 2,214 ⟶ 2,423:
52: upperclassmen -> upperclassman
</pre>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0; \use zero-terminated strings
Line 2,298 ⟶ 2,508:
5 committeeman committeemen
6 committeemen committeeman
7
8
9 complementary complimentary
10 complimentary complementary
11 confirmation conformation
12 conformation confirmation
13
14
15
16
17 craftsperson draftsperson
18 draftsperson craftsperson
|