aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

commit bcf06921c3260c3d37e5d933c2c344e1c1b09102 (patch)
parent 7e3e6f23019ef0e64e7f4a74a0d63067bc6275b1
Author: Alex Karle <alex@alexkarle.com>
Date:   Wed,  7 Dec 2022 21:14:24 -0500

day7: Add part 2 solution

Diffstat:
M2022/07/sol.scm | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/2022/07/sol.scm b/2022/07/sol.scm @@ -5,6 +5,7 @@ ;; Parsing this one is gonna be hard without set! (import srfi-69 ; hash tables (chicken io) + (chicken sort) (chicken irregex) (chicken string)) @@ -40,6 +41,7 @@ (define (add-size-dir! dir) (let ((newsize (+ n (hash-table-ref/default sizes dir 0)))) (hash-table-set! sizes dir newsize))) + ; TODO: would be more efficient to do this after all lines processed (let loop ((dir cwd)) (if (not (equal? dir "")) (begin (add-size-dir! dir) @@ -57,7 +59,14 @@ 'no-op) (else (add-size! (string->number (car parts))))))) +(define (big-enough? n) + (>= n (- 30000000 + (- 70000000 (hash-table-ref sizes "/"))))) + (define (main args) (let ((lines (read-lines))) (for-each parse lines) - (print (apply + (filter (lambda (x) (<= x 100000)) (hash-table-values sizes)))))) + ; (hash-table-for-each sizes (lambda (x n) (print x n))) + (print (apply + (filter (lambda (x) (<= x 100000)) (hash-table-values sizes)))) + (print (car (sort (filter big-enough? (hash-table-values sizes)) + <)))))