1
0
Fork 0

Day 6; some refactoring to use new problem-input-grouped and $.

This commit is contained in:
Jonathan Chan 2020-12-05 22:00:08 -08:00 committed by Jonathan Chan
parent 18f13a4da3
commit 9ae585ebed
5 changed files with 2226 additions and 4 deletions

2199
input/06.txt Normal file

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

16
src/06.rkt Normal file
View File

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