day 6: initial implementation
This commit is contained in:
parent
063bc55cc7
commit
63302f6a3e
|
@ -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"))
|
Loading…
Reference in New Issue