From 459e836026d4c6aba2cacf200b6e68f1dc563348 Mon Sep 17 00:00:00 2001 From: xenia Date: Wed, 7 Dec 2022 00:58:19 -0500 Subject: [PATCH] day 7: idk --- 7.rkt | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) 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)