Advent of Code 2020 solutions in Racket, I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
896 B

#lang racket
(require "lib/common.rkt")
(define string->set (lambda~> string->list list->set))
(define (solution f in)
(for/sum ([ans (in-list in)])
(define answers (map string->set (string-split ans)))
(set-count (foldl f (first answers) (rest answers)))))
(define (day6a in)
(solution set-union in))
(define (day6b in)
(solution set-intersect in))
(module+ main
(call-with-input-file "data/day6.txt"
(lambda (prt)
(define input (string-split (port->string prt) "\n\n"))
(answer 6 1 (day6a input))
(answer 6 2 (day6b input)))))
(module+ test
(require rackunit)
(call-with-input-file "data/day6.txt"
(lambda (prt)
(define input (string-split (port->string prt) "\n\n"))
(check-equal? (day6a input) 6596
"final answer part 1")
(check-equal? (day6b input) 3219
"final answer part 2"))))