class ScalaReversible(max:Int){
import java.lang.Character._
lazy val numReversible = (11 to max).filter(reversible(_)).size
private
def reverse(n:Int)=n + parseInt(n.toString.reverse)
def allOdd(n:Int) = n.toString.map(digit(_,10)).forall(_ % 2 == 1)
def reversible(n:Int) = allOdd(reverse(n))
}
Wednesday, May 20, 2009
JavaOne Talk: Scala Reversible Numbers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment