aboutsummaryrefslogtreecommitdiff
path: root/day06/part1
blob: 00c9b4ce618236695b53eeaa52e10362a82611e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env ruby

def get_depth(hsh, elm)
  n = 0
  loop do
    break if elm == "COM"
    n += 1
    elm = hsh[elm]
  end
  n
end

input = $stdin.readlines.map(&:strip).map{|x|x.split(")")}

objects = {}

input.each do |line|
  objects[line[1]] = line[0]
end

sum = 0
objects.each_key do |obj|
  sum += get_depth(objects, obj)
end

puts sum