Day 3: Use Racket's `in-slice` instead of custom `chunks-of`.
This commit is contained in:
parent
d66bd3ecd6
commit
e509ab16fa
9
lib.rkt
9
lib.rkt
|
@ -260,15 +260,6 @@
|
|||
(define (mmap f lst)
|
||||
(map (∂ map f) lst))
|
||||
|
||||
;; chunks-of : (listof any) -> nonzero? -> (listof (listof any))
|
||||
;; Partitions a list into lists of the given size in order,
|
||||
;; with the final list possibly being smaller
|
||||
;; e.g. '(1 2 3 4 5) 2 => '((1 2) (3 4) (5))
|
||||
(define (chunks-of lst size)
|
||||
(if (< (length lst) size) lst
|
||||
(cons (take lst size)
|
||||
(chunks-of (drop lst size) size))))
|
||||
|
||||
;; transpose : (listof (listof any)) -> (listof (listof any))
|
||||
;; Turns a list of lists into a list of lists of
|
||||
;; the first elements of the lists, ..., the nth elements
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
(priority (unique rucksack))))
|
||||
|
||||
(define part2
|
||||
(for/sum ([rucksacks (chunks-of input 3)])
|
||||
(for/sum ([rucksacks (in-slice 3 input)])
|
||||
(priority (badge rucksacks))))
|
||||
|
||||
(show-solution part1 part2)
|
Loading…
Reference in New Issue