41 lines
1.2 KiB
Text
41 lines
1.2 KiB
Text
find: procedure options (main); /* 20/1/2013 */
|
|
declare word character (20) varying controlled;
|
|
declare dict(*) character (20) varying controlled;
|
|
declare 1 pair controlled,
|
|
2 a character (20) varying, 2 b character (20) varying;
|
|
declare (i, j) fixed binary;
|
|
declare in file;
|
|
|
|
open file(in) title ('/UNIXDICT.TXT,type(LF),recsize(100)');
|
|
on endfile (in) go to completed_read;
|
|
do forever;
|
|
allocate word;
|
|
get file (in) edit (word) (L);
|
|
end;
|
|
|
|
completed_read:
|
|
free word; /* because at the final allocation, no word was stored. */
|
|
allocate dict(allocation(word));
|
|
do i = 1 to hbound(dict,1);
|
|
dict(i) = word; free word;
|
|
end;
|
|
|
|
/* Search dictionary for pairs: */
|
|
do i = 1 to hbound(dict,1)-1;
|
|
do j = i+1 to hbound(dict,1);
|
|
if length(dict(i)) = length(dict(j)) then
|
|
do;
|
|
if dict(i) = reverse(dict(j)) then
|
|
do;
|
|
allocate pair; pair.a = dict(i); pair.b = dict(j);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
put skip list ('There are ' || trim(allocation(pair)) || ' pairs.');
|
|
|
|
do while (allocation(pair) > 0);
|
|
put skip edit (pair) (a, col(20), a); free pair;
|
|
end;
|
|
end find;
|