Changeable words: Difference between revisions

Added Algol 68
m (→‎{{header|Wren}}: Minor tidy)
(Added Algol 68)
Line 162:
upperclassman <-> upperclassmen
</pre>
=={{header|ALGOL 68}}==
<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 ⟶ 330:
underclassman - underclassmen
upperclassman - upperclassmen</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">FileRead, db, % A_Desktop "\unixdict.txt"
3,044

edits