diff options
Diffstat (limited to 'day06/part1')
-rwxr-xr-x | day06/part1 | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/day06/part1 b/day06/part1 new file mode 100755 index 0000000..00c9b4c --- /dev/null +++ b/day06/part1 @@ -0,0 +1,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 |