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)
|
(ft-add-file! file-tree (reverse cwd) file size)
|
||||||
cwd]))
|
cwd]))
|
||||||
|
|
||||||
(define sizes (make-hash))
|
(define sizes '())
|
||||||
|
|
||||||
(define (ft-lookup ft path)
|
(define (record-size! ft)
|
||||||
(match path
|
|
||||||
['() ft]
|
|
||||||
[(cons fst rst) (ft-lookup (hash-ref ft fst) rst)]))
|
|
||||||
|
|
||||||
(define (record-size! ft path)
|
|
||||||
(define size
|
(define size
|
||||||
(for/sum ([(k v) (in-hash (ft-lookup ft path))])
|
(for/sum ([(k v) (in-hash ft)])
|
||||||
(if (number? v)
|
(if (number? v)
|
||||||
v
|
v
|
||||||
(record-size! ft (append path (list k))))))
|
(record-size! v))))
|
||||||
(hash-set! sizes path size)
|
(set! sizes (cons size sizes))
|
||||||
size)
|
size)
|
||||||
|
|
||||||
(record-size! file-tree '())
|
(record-size! file-tree)
|
||||||
|
(sort sizes <))
|
||||||
(sort (hash-values sizes) <))
|
|
||||||
|
|
||||||
(define (part1 input)
|
(define (part1 input)
|
||||||
(define *at-most* 100000)
|
(define *at-most* 100000)
|
||||||
|
|
Loading…
Reference in New Issue