aoc2022/4.rkt

23 lines
561 B
Racket
Raw Normal View History

2022-12-04 05:14:24 +00:00
#lang curly-fn racket
2022-12-04 05:28:16 +00:00
(require "scripts/aoc.rkt")
2022-12-04 05:14:24 +00:00
;; solution for day 4
(define (part1 input)
2022-12-04 05:32:38 +00:00
(count #{member (apply is:union %) %} input))
2022-12-04 05:14:24 +00:00
(define (part2 input)
2022-12-04 05:32:38 +00:00
(count #{is:get-integer (apply is:intersect %)} input))
2022-12-04 05:14:24 +00:00
(define (parse fname)
(for/list ([line (in-list (file->lines fname))])
2022-12-04 05:24:29 +00:00
(map #{~>> (string-split % "-") (map string->number) (apply is:make-range)}
(string-split line ","))))
2022-12-04 05:14:24 +00:00
(module+ main
(define input (parse "inputs/4"))
(answer 4 1 (time (part1 input)))
(answer 4 2 (time (part2 input)))
(displayln "meow"))