From e509ab16fa3837ee7abd43f7322046629edd51a1 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Mon, 5 Dec 2022 23:56:20 -0500 Subject: [PATCH] Day 3: Use Racket's `in-slice` instead of custom `chunks-of`. --- lib.rkt | 9 --------- src/03.rkt | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib.rkt b/lib.rkt index 8b5d77d..24170b8 100644 --- a/lib.rkt +++ b/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 diff --git a/src/03.rkt b/src/03.rkt index 5990615..92d23b8 100644 --- a/src/03.rkt +++ b/src/03.rkt @@ -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) \ No newline at end of file