Taxicab numbers: Difference between revisions
Updated for compatibility with Scala 3
(→{{header|Phix}}: rewrote, syntax coloured, made p2js compatible) |
Keithpinson (talk | contribs) (Updated for compatibility with Scala 3) |
||
Line 3,683:
=={{header|Scala}}==
<lang scala>import scala.
import scala.math.pow
implicit class Pairs[A, B]( p:List[(A, B)]) {
def collectPairs:
}
Line 3,697 ⟶ 3,698:
case _ => 0 ->(0, 0)
} // Turn the list into the sum of two cubes and
.collectPairs // Only keep taxi cab numbers with a duplicate
.toList.sortBy(_._1) // Sort the results
Line 3,713 ⟶ 3,714:
case (p, a::b::Nil) => println( "%20d\t(%d\u00b3 + %d\u00b3)\t(%d\u00b3 + %d\u00b3)".format(p,a._1,a._2,b._1,b._2) )
}
}</lang>▼
▲</lang>
{{out}}
<pre>
|