Skip to content

Instantly share code, notes, and snippets.

@orodriguez
Created April 29, 2013 21:55
Show Gist options
  • Save orodriguez/df96de982866d48748f9 to your computer and use it in GitHub Desktop.
Save orodriguez/df96de982866d48748f9 to your computer and use it in GitHub Desktop.
class Fixnum
def palindrome?
to_s == to_s.reverse
end
end
def parse_range line
Range.new *line.split.map(&:to_i)
end
def count_palindromes file
file.map { |line| parse_range(line).count(&:palindrome?) }.reduce(0, :+)
end
p "Found #{count_palindromes File.open("seed.txt", "r")}"
# ruby-1.9.3
# $ time ruby palindrome.rb
# "Found 106814"
# real 1m6.513s
# user 1m6.452s
# sys 0m0.020s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment