aboutsummaryrefslogtreecommitdiff
path: root/jj-aoc.rkt
blob: 4149f2a288f79143cf84b9da1fd55e115ff2aaa8 (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)
(provide open-day
         transpose
         chunks-by)

(define (open-day n [year 2021])
  (open-aoc-input (find-session) year n #:cache (string->path "./cache")))

(define (transpose xss)
  (apply map list xss))

(define (chunks-by xs [by identity])
  (define (do-chunks-by xs by group result)
    (match* (xs group)
      [('() _) (reverse (cons group result))]
      [((list* h t) '()) (do-chunks-by t by (cons h group) result)]
      [((list* h t) (list* g _))
       #:when (equal? (by h) (by g))
       (do-chunks-by t by (cons h group) result)]
      [((list* h t) _) (do-chunks-by t by (list h) (cons group result))]))
  (do-chunks-by xs by '() '()))