Semordnilap: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,225: | Line 3,225: | ||
drab bard |
drab bard |
||
158 |
158 |
||
</pre> |
|||
=={{header|SNOBOL4}}== |
|||
{{works with|SNOBOL4, SPITBOL for Linux}} |
|||
<lang SNOBOL4> |
|||
* Program: semordnilap.sbl |
|||
* To run: sbl semordnilap.sbl < unixdict.txt |
|||
* Description: A semordnilap is a word (or phrase) that spells |
|||
* a different word (or phrase) backward. "Semordnilap" |
|||
* is a word that itself is a semordnilap. |
|||
* Example: lager and regal |
|||
* Reads file unixdict.txt |
|||
* Comment: Tested using the Spitbol for Linux version of SNOBOL4 |
|||
output = "Some Semordnilap Pairs from File unixdict.txt" |
|||
atable = table(25200,,-1) |
|||
ntable = table(25200,,-2) |
|||
* Read dictionary file into memory |
|||
in1 |
|||
word = input :f(p1) |
|||
count = count + 1 |
|||
atable[word] = word |
|||
ntable[count] = word |
|||
:(in1) |
|||
* Process dictionary to find unique semordnilaps |
|||
p1 |
|||
i = lt(i,count) i + 1 :f(p2) |
|||
newword = atable[reverse(ntable[i])] |
|||
leq(newword,-1) :s(p1) |
|||
ident(ntable[i],newword) :s(p1) |
|||
output = lt(outcount,5) ntable[i] ', ' newword |
|||
atable[ntable[i]] = atable[newword] = -1 |
|||
outcount = outcount + 1 |
|||
:(p1) |
|||
p2 |
|||
output = 'The number of semordnilap pairs is: ' outcount |
|||
END |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Some Semordnilap Pairs from File unixdict.txt |
|||
able, elba |
|||
abut, tuba |
|||
ac, ca |
|||
ah, ha |
|||
al, la |
|||
The number of semordnilap pairs is: 158 |
|||
</pre> |
</pre> |
||