day 9: bad version

This commit is contained in:
xenia 2020-12-09 00:17:51 -05:00
parent 9475d06eba
commit 7c2b008624
1 changed files with 44 additions and 0 deletions

44
9.rkt Normal file
View File

@ -0,0 +1,44 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 9
;; helper functions here
(define (part1 input)
(define vec (list->vector input))
(let/ec exit
(for ([i (in-range 25 (vector-length vec))])
(define valid?
(for*/first ([a (in-range (- i 25) i)] [b (in-range a i)]
#:when (= (vector-ref vec i) (+ (vector-ref vec a) (vector-ref vec b)))) #t))
(unless valid?
(exit (vector-ref vec i))))))
(define (part2 input)
(define pt1 10884537)
(define pt1-i 501)
(let/ec exit
(define vec (list->vector input))
(define (cb args)
(when (= pt1 (apply + args))
(exit (+ (apply min args) (apply max args)))))
(for* ([ct (in-range 3 100)] [i (in-range 0 (- pt1-i ct))])
(define sub (vector-copy vec i (+ i ct)))
(cb (vector->list sub)))))
(module+ test
(require rackunit)
;; tests here
(displayln "no tests :("))
(module+ main
(define input (file->list "inputs/9"))
;; part 1
(answer 9 1 (part1 input))
;; part 2
(answer 9 2 (part2 input))
(displayln "meow"))