diff --git a/7.rkt b/7.rkt index c5f9aef..379b2ef 100644 --- a/7.rkt +++ b/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)