Skip to content

Instantly share code, notes, and snippets.

@hminaya
Last active December 16, 2015 12:38
Show Gist options
  • Save hminaya/5435691 to your computer and use it in GitHub Desktop.
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
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