
@rmathews has joined the channel

I just cut the east-west direction in half <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day24.rkt|in my solution> : (hash "e" 1 "se" (+ 0.5 -i) "ne" (+ 0.5 +i) "w" -1 "sw" (+ -0.5 -i) "nw" (+ -0.5 +i) )
I got a kick out of nesting 3 folds in flip-em
:)

Complex numbers to the rescue again!

That’s interesting @me1890, I didn’t think about the possibility of rounding errors, but I didn’t have an issue on Racket CS 7.9. For your follow-directions
I think I just did (apply + directions)
instead since I converted them to complex numbers first. Not sure if that affects the rounding issue, or not.

I think I’ll change to rational though anyway - seems better.

Oops - that changed run time from 2.5 sec to 4.1 sec, so maybe I won’t !!

I originally tried having both black & white tiles in the hash
, but that seemed to add unwanted complexity, so I switched to only having black tiles in the hash
. To get the set of keys to iterate on, I added all the black keys and all the adjacent keys to those keys to a set. My hashes and sets are all functional, and performance seemed good enough.

I really need to think about using fold when appropriate. I tend to just crank out a named let, <https://github.com/lojic/LearningRacket/commit/e2eabdab5dda2291f0e73630f4d82b446611fc4f#diff–7b4861fcd5703a0c3b0b92596c5e1066e810249520c6dc124b65228288121590|using a fold here> really improved the code IMO.

I’ve actually been moving from using foldl to using named lets and for/fold It’s mostly because I keep forgetting the order of arguments in the fold function, but also because if I have a giant lambda in the fold there’s a) a large indentation level that I’m not fond of and b) I don’t like the way the initial element and list look hanging off the end

Some cases are probably somewhat “gray”, but in my link above, I think there’s a definite improvement from named let to foldl. I’ll have to try a for/fold version and see how I like it.

@jonathanhwchan I do like <https://github.com/lojic/LearningRacket/commit/9a712b32724029aef288ca1d41b00a19eecdfe8a#diff–7b4861fcd5703a0c3b0b92596c5e1066e810249520c6dc124b65228288121590|changing part1
to for/fold
> . Either foldl
or for/fold
improves over the let loop ...
in this case, I think. Thanks for the tip.

@badkins I spent too long learning to use mlton only to get an Overflow exception :smiley: I am going to try using a map instead of a vector—I’m going to keep the map small by assuming the “next” value from cup n is n+1 if it’s not in the map—I wonder if trying to ease the memory pressure will help at all?

I’ve grown in my appreciation for Racket during this AoC. It just always seems to have a nice solution. The for/fold changes brings <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day24.rkt|the code down to 25 lines> (excluding tests).

Just out of curiosity, why SML vs. OCaml ?

I guess you could use mutation either way - are you trying to stay functional for this?

Never learned OCaml, and at this point it’s a whole ecosystem I don’t have time to dive into. I’ll be playing with Coq for a class up-and-coming, though, so maybe? Yeah, for mutation vs. functional I prefer functional, but the Vector wasn’t fast enough so I used mutable Array

I really liked SML when I was fooling around with it, but I got the distinct impression that OCaml was more viable for professional work. It seems more supported, and the Jane Street Capital folks have contributed some good stuff.

So far, the functional-map-based seems roughly the same speed as long mutable arrays, with much less memory pressure (I think)

Well, at least at first. I suspect that as the number of iterations climbs, performance actually drops (you have the large map in memory after all the indices have been touched)

I don’t know why I keep golfing the lines. <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day24-formatted.rkt|More vertical space> is a lot more readable :)

Much more readable :) fyi it might be more concise to use count
instead of for/sum
when you’re just returning 0/1

Good call. I also realized I only need hash-has-key?
, so that allows (curry hash-has-key? hsh)
- https://github.com/lojic/LearningRacket/blob/master/advent-of-code-2020/day24-formatted.rkt\|day24-formatted.rkt

done for the year! :shark::chart_with_upwards_trend::sparkles:

I missed a few part 2’s so i will be at it for a few more days probably

I feel nothing but pain

also I bruteforced Day 20 Part 2

My day 20 part 2 is close, but i need to do some more work with passing around transformation state

I just counted the number of hashes, started at 20 sea monsters, and kept adding and subtracting 15 until it worked

i’m having some trouble with day 19 part 2, that’s being real frustrating right now