Semordnilap: Difference between revisions

Updated for compatibility with Scala 3
m (→‎{{header|Phix}}: syntax coloured, made p2js compatible)
(Updated for compatibility with Scala 3)
Line 3,112:
 
=={{header|Scala}}==
<lang scala>val wordsAll =
<lang scala>val wordsAll = scala.io.Source.fromURL("http://www.puzzlers.org/pub/wordlists/unixdict.txt").getLines.map(_.toLowerCase).to[IndexedSeq]
scala.io.Source.
<lang scala>val wordsAll = scala.io.Source.fromURL("http://wwwwiki.puzzlers.org/pub/wordlists/unixdict.txt").getLines.map(_.toLowerCase).to[IndexedSeq]
getLines().map(_.toLowerCase).toIndexedSeq
 
 
/**
Line 3,119 ⟶ 3,123:
* words are different.
*/
def semordnilap( words:SeqIndexedSeq[String] ) : SeqIndexedSeq[(String,String)] = {
 
( words.
zipWithIndex. // index will be needed to eliminate duplicate
filter {
case (w,i) =>
val j = words.indexOf(w.reverse) // eg. (able,62) and (elba,7519)
i < j && w != w.reverse // save the matches which are not palindromes
) }.
map {
case (w,i_) => (w,w.reverse) // drop the index
}
).
map {
case (w,i) => (w,w.reverse) // drop the index
}
}
 
Line 3,137 ⟶ 3,140:
 
{
println( s"${ss.size + "} matches, including: \n" )
println( ss.take(5).mkString( "\n" ) )
}</lang>
105

edits