Semordnilap: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured, made p2js compatible) |
Keithpinson (talk | contribs) (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.
▲
getLines().map(_.toLowerCase).toIndexedSeq
/**
Line 3,119 ⟶ 3,123:
* words are different.
*/
def semordnilap( 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 {▼
}
▲ ).
▲ map {
▲ case (w,i) => (w,w.reverse) // drop the index
}
Line 3,137 ⟶ 3,140:
{
println( s"${ss.size
println( ss.take(5).mkString( "\n" ) )
}</lang>
|