popa.bogdanp
2020-12-18 10:26:42

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


samth
2020-12-18 14:33:41

@hazel I think either letrec + delay or shared


ben.knoble
2020-12-18 16:07:39

@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


badkins
2020-12-18 19:48:22

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 :)


me1890
2020-12-18 19:51:14

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


badkins
2020-12-18 19:51:22

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.


me1890
2020-12-18 19:51:50

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


badkins
2020-12-18 19:52:15

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


me1890
2020-12-18 19:53:07

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


me1890
2020-12-18 19:54:41

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


badkins
2020-12-18 20:31:46

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!


badkins
2020-12-18 20:32:34

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.


badkins
2020-12-18 20:33:28

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


me1890
2020-12-18 20:34:06

I agree. very nice solution, well done!


badkins
2020-12-18 20:34:46

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.


me1890
2020-12-18 20:35:33

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


me1890
2020-12-18 20:36:20

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


jaz
2020-12-18 21:16:47

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


badkins
2020-12-18 23:12:07

@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?


badkins
2020-12-18 23:13:02

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


jaz
2020-12-18 23:13:55

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



badkins
2020-12-18 23:15:10

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


badkins
2020-12-19 00:03:02

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 :)


badkins
2020-12-19 00:57:29

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?


badkins
2020-12-19 01:06:47

It does look interesting.


haskal
2020-12-19 06:27:17

day 19 spoilers


sorawee
2020-12-19 06:28:06

seriously, the doc of parser-tools kinda sucks.


haskal
2020-12-19 06:28:45

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


haskal
2020-12-19 06:34:24

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


hazel
2020-12-19 07:27:37

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


hazel
2020-12-19 07:27:42

but I stand by that comment 100%