aboutsummaryrefslogtreecommitdiff
path: root/jj-aoc.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'jj-aoc.rkt')
-rw-r--r--jj-aoc.rkt20
1 files changed, 18 insertions, 2 deletions
diff --git a/jj-aoc.rkt b/jj-aoc.rkt
index 62c1523..4149f2a 100644
--- a/jj-aoc.rkt
+++ b/jj-aoc.rkt
@@ -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 '() '()))