aboutsummaryrefslogtreecommitdiff
path: root/aoc2020/day-06/day-06.rkt
blob: b0e2af903415a0e443d31e96ee2cb4703b2aee7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#lang racket
(require "../../jj-aoc.rkt"
         threading)

(define responses (~> (open-day 6 2020) (port->string) (string-split "\n\n")))

;; part 1
(define (response-count-total rs)
  (for/sum ([r (in-list rs)]) (~> r (string-replace _ "\n" "") string->list list->set set-count)))

(response-count-total responses)

;; part 2
(define (response-consensus-total rs)
  (for/sum ([r (in-list rs)])
           (~> r
               (string-split _ "\n")
               (map (λ~> string->list list->set) _)
               (apply set-intersect _)
               set-count)))

(response-consensus-total responses)