Created
April 13, 2013 21:41
-
-
Save perryh/5380183 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? | |
return self.to_s == self.to_s.reverse | |
end | |
def square_of_palindrome? | |
sqrt = Math.sqrt(self) | |
return sqrt.to_i.palindrome? && sqrt - sqrt.to_i.to_f == 0 | |
end | |
end | |
input = File.open("input", "r") | |
num_cases = input.gets.chomp.to_i | |
num_cases.times do |i| | |
count = 0 | |
line = input.gets.chomp.split " " | |
min = line[0].to_i | |
max = line[1].to_i | |
until min == max + 1 | |
if min.palindrome? && min.square_of_palindrome? | |
count += 1 | |
end | |
min += 1 | |
end | |
puts "Case ##{i.to_s}: #{count.to_s}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment