diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2022/day-13 | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2022/day-13')
-rw-r--r-- | aoc2022/day-13/day-13.rkt | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/aoc2022/day-13/day-13.rkt b/aoc2022/day-13/day-13.rkt deleted file mode 100644 index 39435e9..0000000 --- a/aoc2022/day-13/day-13.rkt +++ /dev/null @@ -1,28 +0,0 @@ -#lang racket - -(require advent-of-code) - -(define raw-packets - (parameterize ([current-readtable (make-readtable #f #\, #\space #f)]) - (port->list read (open-aoc-input (find-session) 2022 13 #:cache #true)))) - -(define (compare xs ys) - (match* (xs ys) - [('() (list* _)) #true] - [((list* _) '()) #false] - [((list* _same x-rest) (list* _same y-rest)) (compare x-rest y-rest)] - [((list* (? integer? x) _) (list* (? integer? y) _)) (< x y)] - [((list* (? list? xs*) _) (list* (? list? ys*) _)) (compare xs* ys*)] - [(xs (list* (? integer? y) y-rest)) (compare xs (cons (list y) y-rest))] - [((list* (? integer? x) x-rest) ys) (compare (cons (list x) x-rest) ys)])) - -;; part 1 -(for/sum ([i (in-naturals 1)] [packet (in-slice 2 raw-packets)] #:when (apply compare packet)) i) - -;; part 2 -(define divider-packets (list '((2)) '((6)))) -(define amended-packets (append divider-packets raw-packets)) - -(for/product ([i (in-naturals 1)] [packet (in-list (sort amended-packets compare))] - #:when (member packet divider-packets)) - i) |