diff options
Diffstat (limited to 'jj-aoc.rkt')
-rw-r--r-- | jj-aoc.rkt | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -1,6 +1,22 @@ #lang racket (require advent-of-code) -(provide open-day) +(provide open-day + transpose + chunks-by) (define (open-day n [year 2021]) - (open-aoc-input (find-session) year n #:cache (string->path "./cache")))
\ No newline at end of file + (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 '() '())) |