blob: 1c167a662ac2f393ee6edf8053ee77ef52f73e7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#lang racket
(require advent-of-code
(only-in algorithms sliding))
(define buffer (fetch-aoc-input (find-session) 2022 6))
(define (find-marker data type)
(define n
(case type
[(start-of-packet) 4]
[(start-of-message) 14]))
(for/first ([chunk (in-list (sliding (string->list data) n))]
[i (in-naturals n)]
#:unless (check-duplicates chunk))
i))
;; part 1
(find-marker buffer 'start-of-packet)
;; part 2
(find-marker buffer 'start-of-message)
|