blob: 419d687bd0f69c311d09e36fb393a7ae7a82068d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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))))
|