summary refs log tree commit diff stats
path: root/day6.scm
diff options
context:
space:
mode:
authorbrian <brianmchu42@gmail.com>2024-08-03 13:33:43 -0700
committerbrian <brianmchu42@gmail.com>2024-08-03 13:33:43 -0700
commita88e8da779cd09c398723e4e87e79d945af0994e (patch)
tree0be5a89e050f088ebc166433c4ce251d43062bb4 /day6.scm
downloadAdventOfCode2019-main.tar.gz
initial commit to day 6 main
Diffstat (limited to 'day6.scm')
-rwxr-xr-xday6.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/day6.scm b/day6.scm
new file mode 100755
index 0000000..419d687
--- /dev/null
+++ b/day6.scm
@@ -0,0 +1,24 @@
+#!/usr/bin/env gosh
+(use file.util)
+
+(define (read-input filename)
+  (let ((tree (make-hash-table string-comparator)))
+    (for-each
+      (lambda (x) (hash-table-push! tree (car x) (cadr x)))
+      (map 
+        (cut string-split <> ")")
+        (file->string-list filename)))
+    tree))
+
+(define (count-branch-length mapping key length)
+  (if (hash-table-contains? mapping key)
+    (fold + 0 (map (cut count-branch-length mapping <> (+ length 1))
+                (hash-table-ref mapping key)))
+    (fold + 0 (iota length 1))))
+  
+(define (part1 input)
+  (count-branch-length input "COM" 0))
+
+(define (main args)
+  (let ((input (read-input "inputs/day6test.txt")))
+    (print (part1 input))))
\ No newline at end of file