From 69834486a1b498839de2ef1c9e3982a1fe11f272 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Wed, 8 Dec 2021 02:29:43 -0800 Subject: [PATCH] Day 08: No need for a hash when a function will do. --- src/08.rkt | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/08.rkt b/src/08.rkt index eaff747..e9d9614 100644 --- a/src/08.rkt +++ b/src/08.rkt @@ -7,7 +7,7 @@ (for/list ([entry (problem-input 8)]) (match-let ([(list patterns outputs) (string-split entry " | ")]) (list (map string->list (string-words patterns)) - (map #{sort (string->list %) charlist (string-words outputs)))))) (define part1 (~>> input @@ -15,7 +15,7 @@ (map #{count #{(or/c 2 3 4 7) (length %)} %}) sum)) -(define (config patterns) +(define ((config patterns) segs) (define (digit segments) (findf #{= (length %) segments} patterns)) (define (digits segments) @@ -30,22 +30,23 @@ (define six (set-union (set-subtract eight one) sixes)) (define zero (set-union (set-subtract eight three) (set-subtract eight four) one)) (define two (set-union (set-subtract zero sixes) fives)) - (hash (sort zero char> (second entry) - (map #{hash-ref mapping %}) + (map mapping) list->string string->number))))