rmathews
2020-12-24 14:57:50

@rmathews has joined the channel


badkins
2020-12-24 19:14:22

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


badkins
2020-12-24 19:15:18

Complex numbers to the rescue again!


badkins
2020-12-24 19:20:10

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.


badkins
2020-12-24 19:20:38

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


badkins
2020-12-24 19:21:37

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


badkins
2020-12-24 19:25:45

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.


badkins
2020-12-24 19:33:28

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.


jonathanhwchan
2020-12-24 19:37:48

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


badkins
2020-12-24 19:47:42

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.


badkins
2020-12-24 20:04:39

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


ben.knoble
2020-12-24 20:25:09

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


badkins
2020-12-24 20:26:29

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


badkins
2020-12-24 20:28:10

Just out of curiosity, why SML vs. OCaml ?


badkins
2020-12-24 20:28:44

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


ben.knoble
2020-12-24 20:29:45

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


badkins
2020-12-24 20:32:07

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.


ben.knoble
2020-12-24 20:48:05

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


ben.knoble
2020-12-24 20:48:50

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)


badkins
2020-12-24 23:09:32

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


jonathanhwchan
2020-12-25 00:36:46

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


badkins
2020-12-25 01:53:05

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


haskal
2020-12-25 06:08:41

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


me1890
2020-12-25 06:15:57

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


hazel
2020-12-25 06:20:12

I feel nothing but pain


hazel
2020-12-25 06:20:18

also I bruteforced Day 20 Part 2


me1890
2020-12-25 06:21:16

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


hazel
2020-12-25 06:21:39

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


me1890
2020-12-25 06:21:54

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