Wednesday, May 20, 2009

JavaOne Talk: Scala Reversible Numbers

See this post about why this code is being shown. See this post for the Java version to compare against.

class ScalaReversible(max:Int){
import java.lang.Character._
lazy val numReversible = (11 to max).filter(reversible(_)).size
def reverse(n:Int)=n + parseInt(n.toString.reverse)
def allOdd(n:Int) =,10)).forall(_ % 2 == 1)
def reversible(n:Int) = allOdd(reverse(n))

No comments: