day 7: idk

This commit is contained in:
xenia 2022-12-07 00:58:19 -05:00
parent a58b1b478f
commit 459e836026
1 changed files with 7 additions and 13 deletions

20
7.rkt
View File

@ -27,25 +27,19 @@
(ft-add-file! file-tree (reverse cwd) file size)
cwd]))
(define sizes (make-hash))
(define sizes '())
(define (ft-lookup ft path)
(match path
['() ft]
[(cons fst rst) (ft-lookup (hash-ref ft fst) rst)]))
(define (record-size! ft path)
(define (record-size! ft)
(define size
(for/sum ([(k v) (in-hash (ft-lookup ft path))])
(for/sum ([(k v) (in-hash ft)])
(if (number? v)
v
(record-size! ft (append path (list k))))))
(hash-set! sizes path size)
(record-size! v))))
(set! sizes (cons size sizes))
size)
(record-size! file-tree '())
(sort (hash-values sizes) <))
(record-size! file-tree)
(sort sizes <))
(define (part1 input)
(define *at-most* 100000)