day 6: initial implementation

This commit is contained in:
xenia 2020-12-06 00:07:33 -05:00
parent 063bc55cc7
commit 63302f6a3e
1 changed files with 31 additions and 0 deletions

31
6.rkt Normal file
View File

@ -0,0 +1,31 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 6
;; helper functions here
(define (part1 input)
(for/sum ([grp (in-list input)])
(set-count (for/fold ([s (set)]) ([person (in-list grp)])
(set-union s person)))))
(define (part2 input)
(for/sum ([grp (in-list input)])
(set-count (for/fold ([s (list->set (string->list "abcdefghijklmnopqrstuvwxyz"))])
([person (in-list grp)])
(set-intersect s person)))))
(module+ main
(define input
(for/list ([grp (in-list (string-split (file->string "inputs/6") "\n\n"))])
(for/list ([line (in-list (string-split grp))])
(list->set (string->list line)))))
;; part 1
(answer 6 1 (part1 input))
;; part 2
(answer 6 2 (part2 input))
(displayln "meow"))