Skip to content

Instantly share code, notes, and snippets.

@perryh
Created April 13, 2013 21:41
Show Gist options
  • Save perryh/5380183 to your computer and use it in GitHub Desktop.
Save perryh/5380183 to your computer and use it in GitHub Desktop.
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