Last active
December 16, 2015 12:38
-
-
Save hminaya/5435691 to your computer and use it in GitHub Desktop.
Primer ejemplo en ruby de como encontrar si un numero es un palíndromo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_palindrome?(num) | |
s = num.to_s | |
s == s.reverse | |
end | |
count = 0 | |
File.open("seed.txt") do |f| | |
while line = f.gets | |
one = line.split[0] | |
two = line.split[1] | |
(one..two).each do |x| | |
if is_palindrome?(x) | |
count += 1 | |
end | |
end | |
end | |
end | |
puts "\nFound: #{count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment