diff options
author | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-11-30 17:10:00 -0500 |
commit | 8ab65dc2da1742eb86ec636c50c7018385b68167 (patch) | |
tree | c4fd556aca9b867cfa1f2f174128c30857353884 /2022/day-07 | |
parent | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (diff) | |
download | gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.tar.gz gleam_aoc-8ab65dc2da1742eb86ec636c50c7018385b68167.zip |
prep for 2023, renaming for consistency
Diffstat (limited to '2022/day-07')
-rw-r--r-- | 2022/day-07/day-07.rkt | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/2022/day-07/day-07.rkt b/2022/day-07/day-07.rkt deleted file mode 100644 index 3826cc4..0000000 --- a/2022/day-07/day-07.rkt +++ /dev/null @@ -1,36 +0,0 @@ -#lang racket - -(require advent-of-code - fancy-app - threading - (only-in relation ->number)) - -(define command-output (~> (fetch-aoc-input (find-session) 2022 7) (string-split "\n"))) - -(define (parse-commands cmds) - (define (update-sizes h path size) - (match path - ['() h] - [(list* _ fs) (update-sizes (hash-update h path (+ _ size) 0) fs size)])) - - (for/fold ([folders (hash)] [current-path '()] [previously-seen? #false] #:result folders) - ([cmd (in-list cmds)]) - (match (string-split cmd) - [(list "$" "ls") (values folders current-path (hash-has-key? folders current-path))] - [(list "$" "cd" "/") (values folders '("/") #false)] - [(list "$" "cd" "..") (values folders (rest current-path) #false)] - [(list "$" "cd" folder) (values folders (cons folder current-path) #false)] - [(list "dir" _) (values folders current-path previously-seen?)] - [(list (app ->number size) _) - (cond - [previously-seen? (values folders current-path previously-seen?)] - [else (values (update-sizes folders current-path size) current-path previously-seen?)])]))) - -(define folders (parse-commands command-output)) - -;; part 1 -(for/sum ([(_ v) (in-hash folders)] #:when (<= v 100000)) v) - -;; part 2 -(define required-to-delete (- 30000000 (- 70000000 (hash-ref folders '("/"))))) -(~>> folders hash-values (filter (> _ required-to-delete)) (apply min)) |