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

29
2019/day19/day19.rkt Normal file
View file

@ -0,0 +1,29 @@
#lang racket/base
(require "../intcode.rkt")
(module+ test
(require rackunit))
(define (pulled? program x y)
(define vm (execute (start-machine program (list x y))))
(= 1 (car (machine-outputs vm))))
(define (part1 program)
(length (for*/list ([x (in-range 50)]
[y (in-range 50)]
#:when (pulled? program x y))
(list x y))))
(module+ test
(check-equal? (part1 (parse-file "input")) 229))
(define (part2 program)
(let loop ([x 0] [y 99])
(cond
[(not (pulled? program x y)) (loop (add1 x) y)]
[(pulled? program (+ x 99) (- y 99)) (+ (* 10000 x) (- y 99))]
[else (loop x (add1 y))])))
(module+ test
(check-equal? (part2 (parse-file "input")) 6950903))