1
0
Fork 0

Day 3: Use Racket's `in-slice` instead of custom `chunks-of`.

This commit is contained in:
Jonathan Chan 2022-12-05 23:56:20 -05:00
parent c92c25be29
commit 2f3071017c
2 changed files with 1 additions and 10 deletions

View File

@ -260,15 +260,6 @@
(define (mmap f lst) (define (mmap f lst)
(map ( map 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)) ;; transpose : (listof (listof any)) -> (listof (listof any))
;; Turns a list of lists into a list of lists of ;; Turns a list of lists into a list of lists of
;; the first elements of the lists, ..., the nth elements ;; the first elements of the lists, ..., the nth elements

View File

@ -26,7 +26,7 @@
(priority (unique rucksack)))) (priority (unique rucksack))))
(define part2 (define part2
(for/sum ([rucksacks (chunks-of input 3)]) (for/sum ([rucksacks (in-slice 3 input)])
(priority (badge rucksacks)))) (priority (badge rucksacks))))
(show-solution part1 part2) (show-solution part1 part2)