Taxicab numbers: Difference between revisions

Updated for compatibility with Scala 3
(→‎{{header|Phix}}: rewrote, syntax coloured, made p2js compatible)
(Updated for compatibility with Scala 3)
Line 3,683:
 
=={{header|Scala}}==
<lang scala>import scala.mathcollection.powMapView
import scala.math.pow
 
implicit class Pairs[A, B]( p:List[(A, B)]) {
def collectPairs: MapMapView[A, List[B]] = p.groupBy(_._1).view.mapValues(_.map(_._2)).filterNot(_._2.size<2)
}
 
Line 3,697 ⟶ 3,698:
case _ => 0 ->(0, 0)
} // Turn the list into the sum of two cubes and
// remember what we started with, eg. 28->(1,3)
.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>
105

edits