Refactored Day 16 using new lib.rkt additions for string splitting.
This commit is contained in:
parent
dac4ca5b33
commit
6e1c143815
8
lib.rkt
8
lib.rkt
|
@ -165,6 +165,14 @@
|
|||
(cadar replaces))
|
||||
(rest replaces))))
|
||||
|
||||
;; string-lines : string? -> (listof string?)
|
||||
(define (string-lines str)
|
||||
(string-split str "\n"))
|
||||
|
||||
;; string-csv : string? -> [string? -> a] -> (listof a)
|
||||
(define (string-csv str [f identity])
|
||||
(map f (string-split str ",")))
|
||||
|
||||
|
||||
;; Char helpers ;;
|
||||
|
||||
|
|
|
@ -9,17 +9,17 @@
|
|||
[(regexp #px".+: (\\d+)-(\\d+) or (\\d+)-(\\d+)" (list _ from1 to1 from2 to2))
|
||||
(or/c (integer-in (string->number from1) (string->number to1))
|
||||
(integer-in (string->number from2) (string->number to2)))])
|
||||
(string-split (first input) "\n")))
|
||||
(string-lines (first input))))
|
||||
|
||||
(define any-valid-ranges/c
|
||||
(apply or/c valid-range/cs))
|
||||
|
||||
(define ticket
|
||||
(map string->number (string-split (second (string-split (second input) "\n")) ",")))
|
||||
(string-csv (second (string-lines (second input))) string->number))
|
||||
|
||||
(define tickets
|
||||
(map (λ~> (string-split ",") (map string->number _))
|
||||
(rest (string-split (third input) "\n"))))
|
||||
(map #{string-csv % string->number}
|
||||
(rest (string-lines (third input)))))
|
||||
|
||||
(define part1
|
||||
(for*/sum ([ticket tickets]
|
||||
|
|
Loading…
Reference in New Issue