day 4: sigh
This commit is contained in:
parent
1579a46ba4
commit
bd376b7ff7
|
@ -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"))
|
Loading…
Reference in New Issue