Created
October 22, 2012 15:17
-
-
Save you-ssk/3931986 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
def measure(in_a) | |
rule = { 0=>[-1, 0], 1=>[ 0,-1], 2=>[ 1 ,0], 3=>[ 0, 1] } | |
m = {0=>[0,0]} | |
in_a.each_with_index do |a,i| | |
b = m[a[0]] | |
d = a[1] | |
m[i+1] = [b[0]+rule[d][0],b[1]+rule[d][1]] | |
end | |
t = m.values.transpose | |
[t[0].max-t[0].min+1, t[1].max-t[1].min+1] | |
end | |
a = File.open("input.txt").readlines | |
until a.empty? | |
num = Integer(a.shift) | |
next if num == 0 | |
b = [] | |
(num-1).times{b << a.shift.split.map{|e| Integer(e)}} | |
p measure(b) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment