Skip to content

Instantly share code, notes, and snippets.

@pankoholic
Created July 3, 2012 12:58
Show Gist options
  • Save pankoholic/3039581 to your computer and use it in GitHub Desktop.
Save pankoholic/3039581 to your computer and use it in GitHub Desktop.
Recycled Numbers (google code challange; qualification round 2012)
def pair(a, b)
total = 0
(a...b).each do |n|
((n+1)..b).each do |m|
(0...n.to_s.length).each do |i|
temp = n.to_s[i, n.to_s.length] + n.to_s[0, i]
if temp == m.to_s
total += 1
end
end
end
end
return total
end
t = gets.to_i
(1..t).each do |i|
p = gets.chomp
a = p.split(" ")[0].to_i
b = p.split(" ")[1].to_i
total = pair(a, b)
puts "Case ##{i}: " + total.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment