Created
July 3, 2012 12:58
-
-
Save pankoholic/3039581 to your computer and use it in GitHub Desktop.
Recycled Numbers (google code challange; qualification round 2012)
This file contains hidden or 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
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