Find words whose first and last three letters are equal: Difference between revisions

Added Algol 68
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(Added Algol 68)
Line 10:
{{Template:Strings}}
<br><br>
 
=={{header|ALGOL 68}}==
<lang algol68># find 6 (or more) character words with the same first and last 3 letters #
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
);
INT count := 0;
WHILE STRING word;
get( input file, ( word, newline ) );
NOT at eof
DO
IF INT w len = ( UPB word + 1 ) - LWB word;
w len > 5
THEN
IF word[ 1 : 3 ] = word[ w len - 2 : ]
THEN
count +:= 1;
print( ( word, " " ) );
IF count MOD 5 = 0
THEN print( ( newline ) )
ELSE FROM w len + 1 TO 14 DO print( ( " " ) ) OD
FI
FI
FI
OD;
print( ( newline, "found ", whole( count, 0 ), " words with the same first and last 3 characters", newline ) );
close( input file )
FI</lang>
{{out}}
<pre>
antiperspirant calendrical einstein hotshot murmur
oshkosh tartar testes
found 8 words with the same first and last 3 characters
</pre>
 
=={{header|AWK}}==
3,038

edits