diff options
-rw-r--r-- | 2020/day-14/day-14.rkt | 11 | ||||
-rw-r--r-- | 2022/day-07/day-07.rkt | 14 | ||||
-rw-r--r-- | 2022/day-12/day-12.rkt | 13 |
3 files changed, 25 insertions, 13 deletions
diff --git a/2020/day-14/day-14.rkt b/2020/day-14/day-14.rkt new file mode 100644 index 0000000..9ac339c --- /dev/null +++ b/2020/day-14/day-14.rkt @@ -0,0 +1,11 @@ +#lang racket + +(require advent-of-code + threading + fancy-app + relation + rebellion/binary/bitstring) + +(define instructions (string-split (fetch-aoc-input (find-session) 2020 14) "\n")) + +(~> (number->string 11 2) ->list (map (->number _) _)) diff --git a/2022/day-07/day-07.rkt b/2022/day-07/day-07.rkt index 4ebd3b4..3826cc4 100644 --- a/2022/day-07/day-07.rkt +++ b/2022/day-07/day-07.rkt @@ -15,13 +15,13 @@ (for/fold ([folders (hash)] [current-path '()] [previously-seen? #false] #:result folders) ([cmd (in-list cmds)]) - (match cmd - ["$ ls" (values folders current-path (hash-has-key? folders current-path))] - ["$ cd /" (values folders '("/") #false)] - ["$ cd .." (values folders (rest current-path) #false)] - [(regexp #px"\\$ cd (.+)" (list _ folder)) (values folders (cons folder current-path) #false)] - [(regexp #px"dir (.+)") (values folders current-path previously-seen?)] - [(regexp #px"(.+) (.+)" (list _ (app ->number size) _)) + (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?)])]))) diff --git a/2022/day-12/day-12.rkt b/2022/day-12/day-12.rkt index 9120468..5e0c365 100644 --- a/2022/day-12/day-12.rkt +++ b/2022/day-12/day-12.rkt @@ -35,11 +35,12 @@ (list p neighbor)))) ;; part 1 -(match-define-values (distances _) (dijkstra paths (hash-ref special-points 'start))) -(hash-ref distances (hash-ref special-points 'end)) +(time (match-define-values (distances _) (bfs paths (hash-ref special-points 'start))) + (hash-ref distances (hash-ref special-points 'end))) ;; part 2 -(for/lists (lengths #:result (apply min lengths)) - ([start (in-list (hash-keys terrain-mesh))] #:when (= 0 (hash-ref terrain-mesh start))) - (match-define-values (distances _) (dijkstra paths start)) - (hash-ref distances (hash-ref special-points 'end))) +(time (for/lists + (lengths #:result (apply min lengths)) + ([start (in-list (hash-keys terrain-mesh))] #:when (= 0 (hash-ref terrain-mesh start))) + (match-define-values (distances _) (bfs paths start)) + (hash-ref distances (hash-ref special-points 'end)))) |