day 18: GLOBAL RANK OMG AAAAAAAAAAAAAAAAAAAAAAAAAA

also this code doesn't work
This commit is contained in:
xenia 2020-12-18 00:16:34 -05:00
parent 27b5843a14
commit b2aecd8567
1 changed files with 61 additions and 0 deletions

61
18.rkt Normal file
View File

@ -0,0 +1,61 @@
#lang curly-fn racket
(require "scripts/aoc.rkt" parser-tools/lex parser-tools/yacc (prefix-in : parser-tools/lex-sre))
;; solution for day 18
(define-tokens nums [number])
(define-empty-tokens syms [+ * lp rp eof])
(define the-lexer
(lexer
[whitespace (the-lexer input-port)]
["+" (token-+)]
["*" (token-*)]
["(" (token-lp)]
[")" (token-rp)]
[(:+ (char-set "0123456789")) (token-number (string->number lexeme))]
[(eof) (token-eof)]))
(define the-parser
(parser
[start exp]
[end eof]
[error (lambda args (error "meow" args))]
[tokens nums syms]
[precs (left *)(left +)
(left lp rp)]
[grammar
(exp [(lp exp rp) $2]
[(exp + exp) (+ $1 $3)]
[(exp * exp) (* $1 $3)]
[(number) $1])]))
(define (parse/string str)
(let ([input (open-input-string str)])
(the-parser (lambda () (the-lexer input)))))
;; broken!
(define (part1 input)
(for/sum ([line (in-list input)])
(parse/string line)))
(define (part2 input)
(for/sum ([line (in-list input)])
(parse/string line)))
;; parse input file
(define (parse fname)
(define input (file->lines fname))
input)
(module+ test
(require rackunit)
;; tests here
(displayln "no tests :("))
(module+ main
(define input (parse "inputs/18"))
(answer 18 1 (time (part1 input)))
(answer 18 2 (time (part2 input)))
(displayln "meow"))