0 Replies - 1357 Views - Last Post: 28 September 2011 - 08:09 AM

#1 heyoman1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Number Palindromes

Posted 28 September 2011 - 08:09 AM

Description: Change the 1M to any number you wish (ex: 53.times)Checks up to a certain number (here 1M) of how many palindromes are in 1-n.
c = 1
matches = 0

1000000.times do
   matches += 1 if c.to_s.reverse.eql? c.to_s
   c += 1
end

puts "Reached: #{c} n"
puts "Palindromes: #{matches}"
#=> 1000000
#=> 1998





Is This A Good Question/Topic? 0
  • +

Page 1 of 1