ABC words: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
(Added Algol 68) |
||
Line 8: | Line 8: | ||
Show here every ''ABC word'' in unixdict.txt. |
Show here every ''ABC word'' in unixdict.txt. |
||
<br><br> |
<br><br> |
||
=={{header|ALGOL 68}}== |
|||
<lang algol68># find words that have "a", "b" and "C" in order 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 abc count := 0; |
|||
WHILE STRING word; |
|||
get( input file, ( word, newline ) ); |
|||
NOT at eof |
|||
DO |
|||
IF INT w pos := LWB word; |
|||
INT w max = UPB word; |
|||
INT a pos := w max + 1; |
|||
INT b pos := w max + 1; |
|||
INT c pos := w max + 1; |
|||
char in string( "a", a pos, word ); |
|||
char in string( "b", b pos, word ); |
|||
char in string( "c", c pos, word ); |
|||
a pos < b pos |
|||
AND b pos < c pos |
|||
AND c pos <= w max |
|||
THEN |
|||
abc count +:= 1; |
|||
print( ( whole( abc count, -5 ), ": ", word, newline ) ) |
|||
FI |
|||
OD; |
|||
close( input file ) |
|||
FI</lang> |
|||
{{out}} |
|||
Very similar to other samples so just showing a subset... |
|||
<pre> |
|||
1: aback |
|||
2: abacus |
|||
3: abc |
|||
4: abdicate |
|||
5: abduct |
|||
6: abeyance |
|||
7: abject |
|||
8: abreact |
|||
9: abscess |
|||
... |
|||
29: athabascan |
|||
30: auerbach |
|||
31: diabetic |
|||
32: diabolic |
|||
33: drawback |
|||
... |
|||
53: syllabic |
|||
54: tabernacle |
|||
55: tablecloth |
|||
</pre> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
<lang freebasic> |
<lang freebasic> |