-
-
Save orodriguez/df96de982866d48748f9 to your computer and use it in GitHub Desktop.
This file contains 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
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