
I also had the idea to convert the input into an s-expr, but I assumed part two would be harder than it was (i.e. something w/ dynamic operator precedence) so I implemented shunting yard for part 1 and just changed the precedence table for part 2.
https://github.com/Bogdanp/aoc2020/blob/4021ed7a85eb58f655f38a9069656d64aaaa2ace/day18.rkt

@hazel I think either letrec + delay or shared

@haskal I’m not sure that content is meant to be piped to sh
; it’s an HTML page when I curl it/view it in a browser

I think <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day18.rkt|my solution> might be my most verbose/convoluted/<other bad adjectives> of the contest for me! Been a while since I’ve done any parsing which is probably unusual for most Racketeers. Nice job @jonathanhwchan on the sexp approach and @haskal for getting a global score :)

I just used (port->list read)
for my parsing then the wrote cursed infix-eval
so I could do (infix-eval '(1 + 2 * (3 * 8)))

I think I’ll either do an additional version using either shunting yard or parser tools - probably the latter since I’m not sure I’ll have much use for shunting yard later.

honestly lisp might have made the parsing a little too easy today

Yeah, that’s something I’m ashamed of as a Racketeer - I should’ve exploited that :)

Meanwhile my professor who completes the problems in C took much longer (~2.5h i think he said)

Even though i did get a neat solution, haskal had already finshed before i even thought of that idea.

FYI - I posted the following in my local devs Slack: > I’ve got some work to do if I want to keep calling myself a lisper :) Here’s <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day18.rkt|my quick ’n dirty solution> to AoC Day 18 and here is <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day18-jchan.rkt|Jonathan Chan’s elegant version> - very nice use of match! Very nice work @jonathanhwchan - as I mentioned in the other slack, I’ll have no use for the code I wrote today, but I will be able to use the match
technique you demonstrated, so thanks for that!

I hope you don’t mind me adding your version to my repo. I attributed it to you in both the file name and a comment in the code.

That may be the nicest solution I’ve seen in AoC thus far - for any day.

I agree. very nice solution, well done!

I use match
a lot, but not to that level, and I can see a number of applications for that. I’m going to have to dig into match
more deeply.

I love using match (I come from rust), but racket’s match is so much more powerful than any i’ve seen in other languages

Especially the app
pattern lets me do some funky things that make parsing basic input super easy

@popa.bogdanp I did the same thing, basically.

@haskal I was experimenting with your code from today, and I found something curious: (let ([ input (open-input-string "1+2") ])
(oo-parser (thunk (oo-lexer input))))
(oo-parser (thunk (oo-lexer (open-input-string "1+2"))))
I expected the above two expressions to function identically, but the second one fails. open-input-string
is a procedure, but lexer
and parser
are both syntax, so it appears lexer
is doing something that causes it to fail. Did you run into that while coding, or did you have input
in a let from the start?

parser-tools
could use a few examples. Your solution saved me a bunch of time!

parser-tools
has examples; they’re just in the source code instead of the docs…


lol - in my humble opinion, being in the docs might be more useful. Thanks!

Got a <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day18-arithmetic.rkt|normal arithmetic expression parser> w/ lexer
and parser
thanks to @haskal and @jaz’s example tip (needed for multi-digit numbers), and some more insight into match
from @jonathanhwchan, so it was a productive puzzle for me today :)

Thanks @mbutterick. Does brag
impose any limitations on lexer
and parser
? Put another way, is there anything I can do with lexer
and parser
that I can’t do with brag
?

It does look interesting.

day 19 spoilers

seriously, the doc of parser-tools
kinda sucks.

my original solution was manual and i got an awful rank for taking forever with it my revised solution is literally just brag, thanks @mbutterick for the comments abt it yesterday! https://git.lain.faith/haskal/aoc2020/src/branch/aoc2020/19.rkt

here’s the first revision https://git.lain.faith/haskal/aoc2020/src/commit/da583918e091048ef9599ccf06c47f2a12859c7f/19.rkt hazel read this and was like: “use monads”

to be fair I’m stuck on part 2 with my monadic soln now

but I stand by that comment 100%