Semordnilap: Difference between revisions

Added Wren
(Added Rust solution)
(Added Wren)
Line 3,125:
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,476

edits