34 lines
1,012 B
Text
34 lines
1,012 B
Text
* 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
|