public class GroovyReversible {
final Integer max
final Integer numReversible = 0
public GroovyReversible(max){
this.max = max
this.numReversible = this.countReversible()
}
def countReversible(){
numReversible ?: (11..max).findAll{reversible(it)}.size()
}
def reversible(n){
allOdd(reverse(n))
}
def allOdd(n){
n.toString().toList().collect {it.toInteger()}.every{it % 2 == 1}
}
def reverse(n){
n + n.toString().toList().reverse().join().toInteger()
}
}
Wednesday, May 20, 2009
JavaOne Talk: Groovy Reversible Numbers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment