Odd words: Difference between revisions

Added Algol 68
m (→‎{{header|Phix}}: use GT_LF_STRIPPED)
(Added Algol 68)
Line 9:
{{Template:Strings}}
<br><br>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Based on (and almost identical to) the Alternade Words sample.
<lang algol68># find words where the odd letters also form a word #
# use the associative array in the Associate array/iteration task #
PR read "aArray.a68" PR
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 #
on logical file end( input file, ( REF FILE f )BOOL:
BEGIN
# note that we reached EOF on the #
# latest read #
at eof := TRUE;
# return TRUE so processing can continue #
TRUE
END
);
# returns w split into n parts by taking alternate characters #
PRIO SPLIT = 1;
OP SPLIT = ( STRING w, INT n )[]STRING:
BEGIN
[ n ]STRING result;
FOR r pos FROM LWB result TO UPB result DO result[ r pos ] := "" OD;
INT r pos := 1;
FOR w pos FROM LWB w TO UPB w DO
result[ r pos ] +:= w[ w pos ];
r pos +:= 1;
IF r pos > n THEN r pos := 1 FI
OD;
result
END; # SPLIT #
# build an associative array of the words #
REF AARRAY words := INIT LOC AARRAY;
WHILE STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
words // word := word
OD;
close( input file );
# find the words where the odd letters form a word at least five #
# characters long, the word itself must therefore be at least #
# nine characters long #
REF AAELEMENT e := FIRST words;
WHILE e ISNT nil element DO
IF STRING word = key OF e;
INT w len = ( UPB word + 1 ) - LWB word;
w len >= 9
THEN
[]STRING sub word = word SPLIT 2;
IF words CONTAINSKEY sub word[ 1 ]
THEN
print( ( word, ": " ) );
FROM w len + 1 TO 18 DO print( ( " " ) ) OD;
print( ( sub word[ 1 ], newline ) )
FI
FI;
e := NEXT words
OD
FI</lang>
{{out}}
As with the Alternade Words Algol 68 sample, the output is not sorted, it has been sorted hee for ease of comparison with the other samples' output.
<pre>
barbarian: brain
childbear: cider
corrigenda: cried
gargantuan: grata
headdress: hades
palladian: plain
propionate: point
salvation: slain
siltation: slain
slingshot: sight
statuette: saute
supersede: spree
supervene: spree
terminable: trial
</pre>
 
=={{header|Factor}}==
3,060

edits