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))
|
(cadar replaces))
|
||||||
(rest 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 ;;
|
;; Char helpers ;;
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,17 @@
|
||||||
[(regexp #px".+: (\\d+)-(\\d+) or (\\d+)-(\\d+)" (list _ from1 to1 from2 to2))
|
[(regexp #px".+: (\\d+)-(\\d+) or (\\d+)-(\\d+)" (list _ from1 to1 from2 to2))
|
||||||
(or/c (integer-in (string->number from1) (string->number to1))
|
(or/c (integer-in (string->number from1) (string->number to1))
|
||||||
(integer-in (string->number from2) (string->number to2)))])
|
(integer-in (string->number from2) (string->number to2)))])
|
||||||
(string-split (first input) "\n")))
|
(string-lines (first input))))
|
||||||
|
|
||||||
(define any-valid-ranges/c
|
(define any-valid-ranges/c
|
||||||
(apply or/c valid-range/cs))
|
(apply or/c valid-range/cs))
|
||||||
|
|
||||||
(define ticket
|
(define ticket
|
||||||
(map string->number (string-split (second (string-split (second input) "\n")) ",")))
|
(string-csv (second (string-lines (second input))) string->number))
|
||||||
|
|
||||||
(define tickets
|
(define tickets
|
||||||
(map (λ~> (string-split ",") (map string->number _))
|
(map #{string-csv % string->number}
|
||||||
(rest (string-split (third input) "\n"))))
|
(rest (string-lines (third input)))))
|
||||||
|
|
||||||
(define part1
|
(define part1
|
||||||
(for*/sum ([ticket tickets]
|
(for*/sum ([ticket tickets]
|
||||||
|
|
Loading…
Reference in New Issue