1
0
Fork 0

Refactored Day 16 using new lib.rkt additions for string splitting.

This commit is contained in:
Jonathan Chan 2020-12-15 23:52:52 -08:00 committed by Jonathan Chan
parent dac4ca5b33
commit 6e1c143815
2 changed files with 12 additions and 4 deletions

View File

@ -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 ;;

View File

@ -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]