aboutsummaryrefslogtreecommitdiff
path: root/aoc2020/day-13/day-13.rkt
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2020/day-13/day-13.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2020/day-13/day-13.rkt')
-rw-r--r--aoc2020/day-13/day-13.rkt32
1 files changed, 0 insertions, 32 deletions
diff --git a/aoc2020/day-13/day-13.rkt b/aoc2020/day-13/day-13.rkt
deleted file mode 100644
index b53f045..0000000
--- a/aoc2020/day-13/day-13.rkt
+++ /dev/null
@@ -1,32 +0,0 @@
-#lang racket
-
-(require advent-of-code
- (only-in relation ->number)
- threading)
-
-(define (process-ids str)
- (~> str (string-split ",") (filter-map (λ (s) (string->number s 10 'number-or-false)) _)))
-
-(match-define (regexp #px"(\\d+)\n(.+)" (list _ (app ->number timestamp) raw-bus-ids))
- (fetch-aoc-input (find-session) 2020 13))
-
-(define bus-ids (process-ids raw-bus-ids))
-
-;; part 1
-(for/first ([minute (in-naturals timestamp)]
- #:do [(define departing-bus
- (for/first ([b bus-ids] #:when (= 0 (remainder minute b)))
- b))]
- #:when departing-bus)
- (* departing-bus (- minute timestamp)))
-
-;; part 2
-(for/fold ([step 1] [current-timestamp 1] #:result current-timestamp)
- ([b* (in-list (string-split (string-trim raw-bus-ids) ","))]
- [offset (in-naturals)]
- #:unless (equal? b* "x")
- #:do [(define bus (->number b*))])
- (values
- (* step bus)
- (for/first ([n (in-range current-timestamp +inf.0 step)] #:when (= 0 (remainder (+ n offset) bus)))
- n)))