xfix

xfix

So, uh, what’s the catch with part 2? I just used my part 1 solution, and it worked.

0
Post #11
bjorng

bjorng OP

Erlang Core Team

Eric Wastl (the creator of AOC) doesn’t want to reveal that yet:

0
Post #12
qhwa

qhwa

Here’s my solution powered by the revised homemade intcode computer. :joy:

It took 570ms to finish part2.

It cost me ten minutes or so to debug. What surprised me was that it was a REAL diagnose program, pointing out that I had something wrong with executing opcode 3. It was true, I did not support mode 2 for reading at that moment. :cold_sweat: What an ingenious puzzle!

1
Post #13
xfix

xfix

Interestingly, my solution is using :array and runs relatively quickly.

$ mix test test/day9_test.exs
..

Finished in 0.4 seconds
2 doctests, 0 failures
0
Post #14
cblavier

cblavier

It’s working but it’s really slow : https://github.com/cblavier/advent/blob/master/lib/2019/day5/day5.ex

Any idea of what I should improve in my code?
(my guess is that I’m using a lot of binaries instead of integers)

0
Post #15
qhwa

qhwa

I had a glance, it seems that List.replace_at/3 is used in write_memory. This is quite slow. If a list is under random access and update frequently, Map is preferred.

1
Post #16
alvises

alvises

Just finished mine. As you guys said, the refactoring made to the VM in day5/7 definitively paid off!

Follow the @qhwa suggestion. Use a Map to represent the memory of the VM. Keys are addresses and values are intcodes.
After seeing the code of the people here, I’ve decided to just use a struct with memory, ip, relative_base, input, output, etc. keys. In this way each function just takes a vm (with some other arguments) and returns the updated VM. This makes easier to use pipes in the code.

1
Post #17
alvises

alvises

Is there a benchmarking tool that benchmarks the code speed giving a score that’s independent from the machine’s speed?

0
Post #18
sasajuric

sasajuric

Author of Elixir In Action

Not that I’m aware of. You’d need to run both versions on the same machine.

As an aside, I suspect that the slowness of my solution is due to the usage of streams. Moving to plain recursion might help, but I don’t even want to bother to check this because the execution time is ATM good enough. If at some later challenge it starts causing problems, I’ll see about optimizing it :slight_smile:

2
Post #19
cblavier

cblavier

Thank you guys! :smiling_face_with_sunglasses:
Updated to a Map data structure, and it does all the difference!

CleanShot 2019-12-09 at 17.16.02@2x
CleanShot 2019-12-09 at 17.16.02@2x1118×194 17.1 KB

3
Post #20