aboutsummaryrefslogtreecommitdiff
path: root/day06/part1
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-12-06 10:30:11 +0000
committerNat Lasseter <user@4574.co.uk>2019-12-06 10:30:11 +0000
commit831d048ba23e2b518879be2773dd5abca74a8d3f (patch)
tree9ab1fde4fc53641aacaa1269b1ae610cc3405694 /day06/part1
parent6269dd0d419e27a0457efea260490568d626c1b5 (diff)
Day 06
Diffstat (limited to 'day06/part1')
-rwxr-xr-xday06/part126
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