Jump to content

Semordnilap: Difference between revisions

m
Oops, moved Wren entry into correct alphabetical order.
(Added Wren)
m (Oops, moved Wren entry into correct alphabetical order.)
Line 3,053:
drab - bard
Total Count: 158
</pre>
 
=={{header|Wren}}==
<lang ecmascript>import "io" for File
 
var dict = File.read("unixdict.txt").split("\n")
var wmap = {}
dict.each { |w| wmap[w] = true }
var pairs = []
var used = {}
for (word in dict) {
if (word != "") {
var pal = word[-1..0]
if (word != pal && wmap[pal] && !used[pal]) {
pairs.add([word, pal])
used[word] = true
}
}
System.print("There are %(pairs.count) unique semordnilap pairs in the dictionary.")
System.print("\nIn sorted order, the first five are:")
for (i in 0..4) System.print(" %(pairs[i][0]), %(pairs[i][1])")
System.print("\nand the last five are:")
for (i in -5..-1) System.print(" %(pairs[i][0]), %(pairs[i][1])")</lang>
 
{{out}}
<pre>
There are 158 unique semordnilap pairs in the dictionary.
 
In sorted order, the first five are:
able, elba
abut, tuba
ac, ca
ah, ha
al, la
 
and the last five are:
saw, was
suez, zeus
tort, trot
tv, vt
way, yaw
</pre>
 
Line 3,125 ⟶ 3,167:
al la
158
</pre>
 
=={{header|Wren}}==
<lang ecmascript>import "io" for File
 
var dict = File.read("unixdict.txt").split("\n")
var wmap = {}
dict.each { |w| wmap[w] = true }
var pairs = []
var used = {}
for (word in dict) {
if (word != "") {
var pal = word[-1..0]
if (word != pal && wmap[pal] && !used[pal]) {
pairs.add([word, pal])
used[word] = true
}
}
System.print("There are %(pairs.count) unique semordnilap pairs in the dictionary.")
System.print("\nIn sorted order, the first five are:")
for (i in 0..4) System.print(" %(pairs[i][0]), %(pairs[i][1])")
System.print("\nand the last five are:")
for (i in -5..-1) System.print(" %(pairs[i][0]), %(pairs[i][1])")</lang>
 
{{out}}
<pre>
There are 158 unique semordnilap pairs in the dictionary.
 
In sorted order, the first five are:
able, elba
abut, tuba
ac, ca
ah, ha
al, la
 
and the last five are:
saw, was
suez, zeus
tort, trot
tv, vt
way, yaw
</pre>
 
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.