Day 6; some refactoring to use new problem-input-grouped and $.
This commit is contained in:
parent
18f13a4da3
commit
9ae585ebed
File diff suppressed because it is too large
Load Diff
7
lib.rkt
7
lib.rkt
|
@ -11,6 +11,7 @@
|
|||
|
||||
(provide problem-input
|
||||
problem-input-all
|
||||
problem-input-grouped
|
||||
show-solution
|
||||
|
||||
make-vector-grid
|
||||
|
@ -95,6 +96,12 @@
|
|||
[path (string-append "../input/" filename ".txt")])
|
||||
(read-file path)))
|
||||
|
||||
;; problem-input-grouped : number? -> (listof string?)
|
||||
;; Return contents of input file input/xx.txt as a list of strings,
|
||||
;; where each string is a group of lines separated by newlines.
|
||||
(define (problem-input-grouped n)
|
||||
(string-split (problem-input-all n) "\n\n"))
|
||||
|
||||
;; show-solution : a -> b -> void
|
||||
;; Print part1 and part2 on separate lines.
|
||||
(define (show-solution part1 part2)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
(require "../lib.rkt")
|
||||
|
||||
(define input (problem-input-all 4))
|
||||
(define input (problem-input-grouped 4))
|
||||
|
||||
(define test
|
||||
"ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
|
||||
|
@ -52,7 +52,7 @@ iyr:2011 ecl:brn hgt:59in")
|
|||
(∂r string-split ":")))
|
||||
(∂r string-split " ")
|
||||
(∂r string-replace "\n" " "))
|
||||
(string-split in "\n\n"))]
|
||||
in)]
|
||||
[passports (map (∂ foldl passport-set default-passport)
|
||||
passport-entries)]
|
||||
[valid-raw? (struct/c passport string? string? string? string? string? string? string? any/c)]
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
(define input (map string->seat (problem-input 5)))
|
||||
|
||||
(define-values (part1 part2)
|
||||
(let* ([minimum (apply min input)]
|
||||
[maximum (apply max input)]
|
||||
(let* ([minimum ($ min input)]
|
||||
[maximum ($ max input)]
|
||||
[seats (list->set (range minimum (add1 maximum)))]
|
||||
[filled (list->set input)])
|
||||
(values maximum (set-first (set-subtract seats filled)))))
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#lang racket
|
||||
|
||||
(require racket/set
|
||||
"../lib.rkt")
|
||||
|
||||
(define (parse group)
|
||||
(map (∘ list->set string->list) (string-split group "\n")))
|
||||
|
||||
(define input (map parse (problem-input-grouped 6)))
|
||||
|
||||
(define-values (part1 part2)
|
||||
(let* ([any-counts (map (∘ set-count ($ set-union)) input)]
|
||||
[all-counts (map (∘ set-count ($ set-intersect)) input)])
|
||||
(values (sum any-counts) (sum all-counts))))
|
||||
|
||||
(show-solution part1 part2)
|
Loading…
Reference in New Issue