Wednesday, May 20, 2009

JavaOne Talk: Ruby Reversible Numbers

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

class RubyReversible
def initialize(max)
@max = max
@numReversible = nil
end

def allOdd(n)
digits = n.to_s.split(//)
digits.length == digits.map{|c| c.to_i}.select{|i|
i % 2 == 1}.length
end

def reverse(n)
n + n.to_s.reverse.to_i
end

def reversible(n)
allOdd(reverse(n))
end

def countReversible()
@numReversible ||= (11..@max).select{|i|
reversible(i)}.length
@numReversible
end
end

1 comment:

Chethu Apponix said...

Very good information. Its very useful for me. We have a good career in java. We need learn from real time examples and for this we choose good training institute, we need to learn from experts . We need a good training institute for our learning . so people making use of the free demo classes.Many training institute provides free demo classes. One of the best training institute in Bangalore is Apponix Technologies.
https://www.apponix.com/Java-Institute/Java-Training-Institute-in-Bangalore.html