Initial commit

This commit is contained in:
Dimitri Lozeve 2024-11-12 21:43:32 +01:00
commit f242d2b0df
420 changed files with 62521 additions and 0 deletions

37
2020/day06/day06.rkt Normal file
View file

@ -0,0 +1,37 @@
#lang racket
(module+ test
(require rackunit))
(module+ main
(displayln "Day 6"))
(define (read-input filename)
(string-split (file->string filename) "\n\n"))
(define (count-unique str)
(set-count (set-remove (list->set (string->list str)) #\newline)))
(define (part1 filename)
(apply + (map count-unique (read-input filename))))
(module+ test
(check-equal? (part1 "test") 11))
(module+ main
(displayln (part1 "input")))
(define (count-intersection str)
(define answers (string-split str "\n"))
(set-count
(apply set-intersect
(map (compose list->set string->list) answers))))
(define (part2 filename)
(apply + (map count-intersection (read-input filename))))
(module+ test
(check-equal? (part2 "test") 6))
(module+ main
(displayln (part2 "input")))