badkins
2020-12-22 19:06:45

I ended up mainly golfing a bit, but <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day22.rkt|my part 2> is 0.8 seconds, and I didn’t think about optimizing it.


me1890
2020-12-22 19:08:27

doh, i didn’t think to use a named let. I just used do loops for my solution


me1890
2020-12-22 19:08:36

Yours looks much nicer i think


badkins
2020-12-22 19:08:50

Thanks to looking at @mbutterick’s solution (after I created mine), I was able to collapse parts 1 & 2 by passing a recur? flag - that was a nice touch of his :)


badkins
2020-12-22 19:08:58

Knocked it down to 21 sloc.


me1890
2020-12-22 19:09:09

nice


badkins
2020-12-22 19:10:32

I’d be curious to find out where some of the time loss above is coming from.


badkins
2020-12-22 19:11:07

In general, I find that a named let w/ tail recursion almost always performs really well.


me1890
2020-12-22 19:11:51

Yeah, yours probably performs much better because it uses tail recursion better


me1890
2020-12-22 19:12:17

@haskal what form did you use to make the loop in your part 2?


ben.knoble
2020-12-22 23:11:21

I had ~4.5 seconds for p2 w/o optimization, using functional queues (double-list based, I think). Really curious if I can get sub-second, but I don’t have time to spend cranking on it.


badkins
2020-12-22 23:13:29

I just used (append (cdr deck1) (list card1 card2)) to put the two cards on the bottom of the deck. Are the functional queues really slow @ben.knoble?


ben.knoble
2020-12-22 23:14:25

They’re supposed to be amortized O(1), but maybe after dinner I’ll try a version using pure lists and time it.


badkins
2020-12-22 23:15:33

FWIW I’m using Racket CS 7.9 on (16-inch, 2019) macbook pro.


jaz
2020-12-22 23:20:03

Yeah, we’re all using different hardware and different inputs. I don’t know there’s much to be gained from these kind of comparisons.


badkins
2020-12-22 23:23:40

Good point. I had counters for game & round while I was debugging, but I removed them. Knowing how many sub games & rounds were used would help in comparing. I hadn’t thought about the possibility that different data might cause a 8x slowdown.


badkins
2020-12-22 23:25:07

@jaz are you posting your code to github? I could run it on my input and compare.


jaz
2020-12-22 23:26:02

no, my advent code is complete dogshit


jaz
2020-12-22 23:27:28

I can’t even bring myself to save the buffers in DrRacket. That’s how ugly it is.


badkins
2020-12-22 23:27:45

lol - most of mine is also, but I still publish it :) I often start a puzzle with the idea of coding it really well (i.e. as I might do professionally), but then I inevitably end up golfing a bit for no reason.


jaz
2020-12-22 23:27:55

There’s a big line of “Untitled” tabs across my screen


badkins
2020-12-22 23:31:16

Well, if anyone’s curious about the performance of named let w/ simple lists vs. queues, etc., you can grab https://github.com/lojic/LearningRacket/blob/master/advent-of-code-2020/day22.rkt\|day22.rkt and my input file https://github.com/lojic/LearningRacket/blob/master/advent-of-code-2020/day22.txt\|day22.txt and compare.


haskal
2020-12-22 23:38:01

input runtimes may vary wildly, like i added memoization to mine and it runs now in 10 seconds (BC, 2016 laptop) on my input but in 5 seconds on @jonathanhwchan’s input



badkins
2020-12-23 00:22:19

I just ran on my input (0.74 sec) and Jonathan Chan’s input (0.44 sec) and Matthew Butterick’s input (1.2 sec) and Graham’s input (1.2 sec). So yeah, very data dependent, which makes sense.


me1890
2020-12-23 00:23:12

but we can still compare on orders of magnitude even though not directly. My code takes 12 seconds to run, so i know you’re doing something better than me


me1890
2020-12-23 00:23:35

you could also try runnning all those inputs on my code if you want


haskal
2020-12-23 07:07:18

day 23 spoilers in thread


haskal
2020-12-23 07:08:03

https://git.lain.faith/haskal/aoc2020/src/branch/aoc2020/23.rkt this ends up being reasonably fast so i am happy with it


haskal
2020-12-23 07:13:03

so here’s the interesting thing… if i replace all the mutable cons operations with unsafe- variants the execution time actually doubles

why is that? how come unsafe is 2x slower??


haskal
2020-12-23 07:18:37

update: this happens when i redefine the mutable ops like (define mcar unsafe-mcar) (define mcdr unsafe-mcdr) (define set-mcar! unsafe-set-mcar!) (define set-mcdr! unsafe-set-mcdr!) if i instead rewrite using a macro (define-simple-macro (mcar x) (unsafe-mcar x)) (define-simple-macro (mcdr x) (unsafe-mcdr x)) (define-simple-macro (set-mcar! l x) (unsafe-set-mcar! l x)) (define-simple-macro (set-mcdr! l x) (unsafe-set-mcdr! l x)) then there’s no slowdown