aboutsummaryrefslogtreecommitdiff
path: root/2022/day-06/day-06.rkt
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-12-06 00:48:17 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-12-06 00:48:17 -0500
commitdee026d9be9756f9b19e278724543b51a69dd048 (patch)
tree7aef7dc3f349dec971abaeb2c17bcb896fd13fb0 /2022/day-06/day-06.rkt
parent5abb472942f93ca1edebd0bc59df0a26c8dde38a (diff)
downloadgleam_aoc-dee026d9be9756f9b19e278724543b51a69dd048.tar.gz
gleam_aoc-dee026d9be9756f9b19e278724543b51a69dd048.zip
day 6 complete
Diffstat (limited to '2022/day-06/day-06.rkt')
-rw-r--r--2022/day-06/day-06.rkt24
1 files changed, 24 insertions, 0 deletions
diff --git a/2022/day-06/day-06.rkt b/2022/day-06/day-06.rkt
new file mode 100644
index 0000000..4eb8323
--- /dev/null
+++ b/2022/day-06/day-06.rkt
@@ -0,0 +1,24 @@
+#lang racket
+
+(require advent-of-code
+ threading
+ (only-in relation ->list ->set)
+ (only-in algorithms sliding))
+
+(define buffer (~> (fetch-aoc-input (find-session) 2022 6)))
+
+(define (find-marker data type)
+ (define n
+ (match type
+ ['start-of-packet 4]
+ ['start-of-message 14]))
+ (for/first ([chunk (in-list (sliding (->list data) n))]
+ [i (in-naturals n)]
+ #:when (= n (~> chunk remove-duplicates length)))
+ i))
+
+;; part 1
+(find-marker buffer 'start-of-packet)
+
+;; part 2
+(find-marker buffer 'start-of-message)