Words containing "the" substring: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
(Added Algol 68) |
||
Line 6: | Line 6: | ||
The length of any word shown should have a length <big>'''> 11</big>. |
The length of any word shown should have a length <big>'''> 11</big>. |
||
=={{header|ALGOL 68}}== |
|||
<lang algol68># find 11 character (or more) words that have "the" in them # |
|||
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 the 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 > 11 |
|||
THEN |
|||
BOOL found the := FALSE; |
|||
FOR w pos FROM LWB word TO UPB word - 2 WHILE NOT found the DO |
|||
IF word[ w pos : w pos + 2 ] = "the" THEN |
|||
found the := TRUE; |
|||
the count +:= 1; |
|||
print( ( word, " " ) ); |
|||
IF the count MOD 6 = 0 |
|||
THEN print( ( newline ) ) |
|||
ELSE FROM w len + 1 TO 18 DO print( ( " " ) ) OD |
|||
FI |
|||
FI |
|||
OD |
|||
FI |
|||
OD; |
|||
print( ( newline, "found ", whole( the count, 0 ), " ""the"" words", newline ) ); |
|||
close( input file ) |
|||
FI</lang> |
|||
{{out}} |
|||
<pre> |
|||
authenticate chemotherapy chrysanthemum clothesbrush clotheshorse eratosthenes |
|||
featherbedding featherbrain featherweight gaithersburg hydrothermal lighthearted |
|||
mathematician neurasthenic nevertheless northeastern northernmost otherworldly |
|||
parasympathetic physiotherapist physiotherapy psychotherapeutic psychotherapist psychotherapy |
|||
radiotherapy southeastern southernmost theoretician weatherbeaten weatherproof |
|||
weatherstrip weatherstripping |
|||
found 32 "the" words |
|||
</pre> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |