day 7: idk
This commit is contained in:
parent
a58b1b478f
commit
459e836026
20
7.rkt
20
7.rkt
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue