samth
2020-12-15 14:07:50

That’s very odd


samth
2020-12-15 14:07:59

Can you post the code somewhere?


badkins
2020-12-15 15:02:41

You have: (check-equal? (solve-2) 939490236001473) but the solution to part 2 is 640856202464541


badkins
2020-12-15 15:07:05

Thanks for the explanation. I was so close! Looking at some notes I scribbled - I solved for bus ids 7 & 13 w/ 77 and 78 timestamps, and I see a 91 I circled (7 * 13). I was trying to see the relation between 91 and the timestamps, but didn’t think to just add 91 :)


badkins
2020-12-15 15:28:29

lol - that’s funny - I had no idea about that!


badkins
2020-12-15 15:28:59

This has to be a ton of work for the organizer.


badkins
2020-12-15 15:30:04

Hard enough to come up with good puzzles and ensure they’re bug-free, but to have individualized inputs also seems to add a lot of work depending on the puzzle.


ben.knoble
2020-12-15 16:03:12

IIRC there are some parsing techniques that can generate generators as well, so Eric may be able to leverage something like that.


badkins
2020-12-15 17:25:15

Thanks for the nudge! I’ve been really enjoying my first time with AoC, so I badged up despite having “C++” in the name ;)


badkins
2020-12-15 17:28:56

@me1890 how did you come to know about Van Eck’s sequence?


me1890
2020-12-15 17:30:19

It was covered in a numberphile video in June 2019. https://youtu.be/etMJxB-igrc


me1890
2020-12-15 17:30:40

I just so happend to still have the code i wrote while watching that video


hazel
2020-12-15 19:14:44

@samth…for whatever reason, this showed up while I was testing but not when I tried to replicate this behavior explicitly


hazel
2020-12-15 19:15:49

regardless, my friend and I engineered similar solutions, and they also noted a significant improvement with begin0 — I can ask them, I guess?


samth
2020-12-15 19:16:08

was it perhaps when debugging was on in DrRacket?


hazel
2020-12-15 19:16:24

I am not using DrRacket


hazel
2020-12-15 20:15:39

redid Day 15 using a vector in Typed Racket, solves Part 2 in around 1.1 seconds on my machine: https://git.knightsofthelambdacalcul.us/hazel/advent-of-code-2020/src/branch/canon/day15.rkt anyone have any faster solutions without using racket/unsafe/ops?


hazel
2020-12-15 20:23:28

also the hash table solution is much slower here, for some reason.


badkins
2020-12-15 20:51:39

For comparison, my naive, brute force, <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-mutable-hash.rkt|mutable hash table solution> takes 6.2 seconds on a 16" macbook pro.


badkins
2020-12-15 21:05:54

Using a <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-vector.rkt|mutable vector> instead of the mutable hash table brings it down to 0.82 seconds using #lang racket on Racket v7.9 [cs]


notjack
2020-12-15 21:44:05

There’s also tricks he has to consider, like making sure to generate inputs that satisfy some invariants that aren’t actually stated in the rules but which are necessary to avoid pathological behavior


me1890
2020-12-15 21:45:39

Like the buses being prime in day 13 or there being no gaps of two in day 10


me1890
2020-12-15 21:46:12

I’m guessing he just has a program that generates random values inside suitable distributions then replaces them in the input


ben.knoble
2020-12-15 21:48:43

Right, reminds me a bit of Haskell’s quickcheck framework


me1890
2020-12-15 21:49:19

I’ve heard of that, but only used something similar in rust.


badkins
2020-12-15 22:01:16

Lastly, a <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.jl|newbie Julia version> takes about 0.43 seconds. That makes me pretty pleased with the 0.82 second Racket version.


badkins
2020-12-15 22:32:45

By the way, are you using Racket’s time to time your code, or are you timing it from the shell i.e. including load time?


hazel
2020-12-15 22:42:20

time. I am using Racket BC and thus the VM startup time kinda sucketh


hazel
2020-12-15 22:48:23

chez would probably help. only using BC because I’m too lazy to change the NixOS derivation.


haskal
2020-12-15 22:53:36

i implemented a solution with fxvector and unsafe fx ops which brings like 10–20% improvement over plain vectors


badkins
2020-12-15 23:34:51

This is interesting, I did <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.c|a C version> based on the <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.jl|Julia version> and it came in at 0.64 seconds - in between Julia and Racket ! It’s been decades since I coded C seriously, so I may have done something stupid.


soegaard2
2020-12-15 23:36:43

Try a Chez Scheme version next!


badkins
2020-12-15 23:38:45

I don’t even have Chez installed at the moment, and I’m pretty tapped out on this by now :) Bottom line - I’m pleased with Racket’s speed, and if I need more, I’ll use Julia :)


badkins
2020-12-15 23:39:31

Although, now I am curious about fxvector given @haskal’s comments above!


badkins
2020-12-15 23:53:57

Ok, last one :) <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-unsafe-vector.rkt|Unsafe vector/arithmetic version> comes in at 0.75 seconds. @soegaard2 I would think Chez would be similar, but I’m not really sure.


badkins
2020-12-15 23:55:01

So, the immutable hash table version is about 24x slower than the unsafe vector version.


badkins
2020-12-16 00:00:50

Sorry for the noise, but to have all the results in one table: <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.rkt|Racket w/ immutable hash table> => ~ 18 seconds <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-mutable-hash.rkt|Racket w/ mutable hash table> => ~ 6 seconds <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-vector.rkt|Racket w/ mutable vector> => 0.82 seconds <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15-unsafe-vector.rkt|Racket w/ unsafe vector/arithmetic> => 0.68 seconds <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.c|C version> => 0.47 seconds <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2020/day15.jl|Julia w/ mutable vector> => 0.41 seconds


soegaard2
2020-12-16 00:04:39

Racket/ unsafe vector/arithmetic =&gt; 0.75 seconds C version =&gt; 0.64 seconds That’s pretty close!


badkins
2020-12-16 00:08:47

Yes, and I’d be fine with the 0.82 seconds with regular vectors to avoid the clutter of fx...


jaz
2020-12-16 00:14:10

@badkins racket/fixnum doesn’t provide unsafe operations. They check that their inputs are fixnums.


badkins
2020-12-16 00:14:37

Ah!


jaz
2020-12-16 00:14:56

I don’t think your vector ops are unsafe either.


jaz
2020-12-16 00:15:07

You’ll need racket/unsafe/ops variants


badkins
2020-12-16 00:18:26

on it …


badkins
2020-12-16 00:22:06

0.68 seconds - I’ll update the table ^


badkins
2020-12-16 00:29:03

Changing the vector initialization of the C version dropped it from 0.64 to 0.59s


hazel
2020-12-16 03:25:18

while playing with racket/unsafe/ops to make my solution fast(tm) I have successfully caused DrRacket to segfault for the first time


hazel
2020-12-16 03:25:25

please clap


hazel
2020-12-16 03:29:31

more unsafe -> program go fast -> win


hazel
2020-12-16 03:31:56

what’s notable (and odd) is that my Typed Racket solution, my unsafe solution, and @badkins’s unsafe solution all run in around the same time on my machine (around 1200 ms)


samth
2020-12-16 03:32:35

Typed Racket ought to be producing similar code to your use of unsafe


hazel
2020-12-16 03:33:21

this confirms my theory that Typed Racket good


hazel
2020-12-16 03:35:23

this happens with PLT_TR_NO_OPTIMIZE though (albeit I’m not familiar with Typed Racket enough to know if this makes a difference here)


haskal
2020-12-16 06:25:24

day 16 spoilers


haskal
2020-12-16 06:26:12

in the interest of minimizing amount of code i used maximum-bipartite-matching from graph for part 2 i think this is a pretty neat solution https://git.lain.faith/haskal/aoc2020/src/commit/dc4fb90f0808bc08a0048d59f8dd800cfdac44ea/16.rkt#L17


me1890
2020-12-16 06:37:19

wow, that is so much nicer than what i made


me1890
2020-12-16 06:37:48

I made some very ugly code for today


haskal
2020-12-16 06:40:47

note i usually make revisions. if you wanna see the first version see the history. it’s pretty bad (aoc is a tradeoff between code quality and your submission time and i’m optimizing for both because reasons)


me1890
2020-12-16 06:41:39

I honestly don’t know how to write this nicely in racket. Could you tell me how to write these loops better? https://gitlab.com/-/snippets/2050872


me1890
2020-12-16 06:42:54

I can explain parts if it doesn’t make sense


hazel
2020-12-16 06:46:02

my first recommendation would be to dump the let* and use internal defines


hazel
2020-12-16 06:46:14

and define helper functions. a lot of them


hazel
2020-12-16 06:46:57

i am going to see if i can solve this problem in rosette later


hazel
2020-12-16 06:46:59

but for now i sleep


me1890
2020-12-16 06:47:59

I will try to make some helper functions. Thanks for the tips