1
0
Fork 0

Day 21 lol

This commit is contained in:
Jonathan Chan 2022-12-21 00:18:01 -08:00
parent 3e3a03e517
commit 3b52cc2dd2
3 changed files with 3389 additions and 0 deletions

1679
src/21-part1.rkt Normal file

File diff suppressed because it is too large Load Diff

1679
src/21-part2.rkt Normal file

File diff suppressed because it is too large Load Diff

31
src/21.rkt Normal file
View File

@ -0,0 +1,31 @@
#lang racket
(require "../lib.rkt")
(let ([bindings
(for/list ([yell (problem-input 21)])
(match yell
[(pregexp "(\\w+): (\\d+)" `(,_ ,monkey ,n))
(format "(define (~a) ~a)" monkey n)]
[(pregexp "(\\w+): (\\w+) (\\+|-|\\*|/) (\\w+)" `(,_ ,monkey ,monkey1 ,op ,monkey2))
(format "(define (~a) (~a (~a) (~a)))" monkey op monkey1 monkey2)]))])
(display-lines-to-file
`(,"#lang racket" ,@bindings "(root)")
"21-part1.rkt" #:exists 'replace))
(let ([bindings
(for/list ([yell (problem-input 21)])
(match yell
[(pregexp "humn: \\d+" `(,_))
"(define-symbolic humn integer?)"]
[(pregexp "root: (\\w+) (\\+|-|\\*|/) (\\w+)" `(,_ ,monkey1 ,op ,monkey2))
(format "(define (root) (assert (eq? (~a) (~a))))" monkey1 monkey2)]
[(pregexp "(\\w+): (\\w+) (\\+|-|\\*|/) humn" `(,_ ,monkey ,monkey1 ,op))
(format "(define (~a) (~a (~a) humn))" monkey op monkey1)]
[(pregexp "(\\w+): (\\d+)" `(,_ ,monkey ,n))
(format "(define (~a) ~a)" monkey n)]
[(pregexp "(\\w+): (\\w+) (\\+|-|\\*|/) (\\w+)" `(,_ ,monkey ,monkey1 ,op ,monkey2))
(format "(define (~a) (~a (~a) (~a)))" monkey op monkey1 monkey2)]))])
(display-lines-to-file
`(,"#lang rosette/safe" ,@bindings "(evaluate humn (solve (root)))")
"21-part2.rkt" #:exists 'replace))