day 4: sigh

This commit is contained in:
xenia 2022-12-04 00:14:24 -05:00
parent 1579a46ba4
commit bd376b7ff7
2 changed files with 1035 additions and 0 deletions

35
4.rkt Normal file
View File

@ -0,0 +1,35 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 4
(define (part1 input)
(for/sum ([line (in-list input)])
(match-define (list (cons a b) (cons c d)) line)
(if (or (and (>= a c) (<= b d))
(and (>= c a) (<= d b)))
1 0)))
(define (part2 input)
(for/sum ([line (in-list input)])
(match-define (list (cons a b) (cons c d)) line)
(if (or (and (>= a c) (<= a d))
(and (>= c a) (<= c b))
(and (>= b c) (<= b d))
(and (>= d a) (<= d b)))
1 0)))
(define (parse fname)
(for/list ([line (in-list (file->lines fname))])
(match-define (list l r) (string-split line ","))
(match-define (list a b) (string-split l "-"))
(match-define (list c d) (string-split r "-"))
(list (cons (string->number a) (string->number b))
(cons (string->number c) (string->number d)))))
(module+ main
(define input (parse "inputs/4"))
(answer 4 1 (time (part1 input)))
(answer 4 2 (time (part2 input)))
(displayln "meow"))

1000
inputs/4 Normal file

File diff suppressed because it is too large Load Diff