adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
Mario C. 2019-12-09T05:28:48.456100Z

I was afraid of this. Another intcode problem >.<

😂 1
yuhan 2019-12-09T05:53:56.457500Z

it feels like these Intcode problems favour imperative languages which can just bash at a mutable Turing machine tape 😕

fellshard 2019-12-09T05:55:05.458400Z

Perhaps. But you can always find ways to express it more neatly in Lisp. 🙂

fellshard 2019-12-09T05:55:28.459200Z

Seems likely to be the last, though, because we've now been told we have 'a complete Intcode computer' ...

fellshard 2019-12-09T05:55:46.459700Z

Unless we start making more chains of the things

yuhan 2019-12-09T05:56:06.459900Z

I wonder when there'll be a lambda calculus based puzzle 🔥

fellshard 2019-12-09T05:58:17.460300Z

It is neat to see which bits of existing instructions I needed to make more robust

fellshard 2019-12-09T05:58:52.461Z

My memory access functions got abstracted away from the vector representation hard in this problem

yuhan 2019-12-09T06:00:35.462600Z

Yeah, it was a really neat testament to Clojure's Associative abstraction that I could just substitute my vector representation of the tape with a hash-map, and pretty much zero refactoring

👍 1
fellshard 2019-12-09T06:06:10.463200Z

I just ended up extending the vector if setting beyond range

fellshard 2019-12-09T06:07:03.464200Z

But if it was truly sparse memory access, I'd definitely have to push it to either a map or a bunch of map-indexed blocks (0-999, 3000-3999, etc.)

fellshard 2019-12-09T06:07:12.464500Z

But I reaaaally didn't want to go full B-Tree 😛

fellshard 2019-12-09T06:07:16.464700Z

And it seemed to work fine

yuhan 2019-12-09T06:14:15.466600Z

All I did was v -&gt; (into {} (map-indexed vector v)) , solved a NPE by giving get a default value, and everything else automatically worked, it was quite magical

mpcjanssen 2019-12-09T06:16:54.467100Z

much longer run time?

fellshard 2019-12-09T06:17:34.467700Z

Shouldn't be, since you're only modifying one entry at a time; should be mostly reused per each tick

fellshard 2019-12-09T07:02:56.468600Z

Hmm. The visualization's getting to the point where it's minimally useful, I suspect. And the size of the vector's making re-rendering every cell each frame rather prohibitive.

mpcjanssen 2019-12-09T07:51:33.469700Z

argh , reading opcode 9 adjusts the base

🙂 1
fellshard 2019-12-09T08:13:28.470500Z

http://quil.info/sketches/show/a86e31254e4e2b7275aa6363279390b7d369d44b0dfd5d6da33f8039e9163fb9 - Color only, since the memory size is far larger and it starts slowing down frames - and don't have the time to implement a 'dirty cells only' routine

mpcjanssen 2019-12-09T09:45:32.473300Z

hmm seems i keep failong the input test. opcode 203 this should store the input relative to base right?

uosl 2019-12-09T09:48:31.474200Z

I'm having the same problem, with the puzzle input outputting 203. I've tried storing the input at many different ways, but no luck

uosl 2019-12-11T20:36:41.081200Z

Thanks! After looking at your message and my code a few hundred times I finally got it working [=

rjray 2019-12-09T09:48:55.474500Z

Funny, I'm stuck at the same point.

gbouvier 2019-12-09T09:49:28.474600Z

i.e. if base is 10 and the instruction is 203,-5 store the input value in index 5

gbouvier 2019-12-09T09:50:57.474800Z

It is a postition, I messed this up by trying to store at the index of the value at index 5.

mpcjanssen 2019-12-09T09:54:42.475600Z

seems very likely

mpcjanssen 2019-12-09T09:54:58.476500Z

so a target has also rel to base addressing

gbouvier 2019-12-09T09:55:21.477200Z

If the quine works for you (with it's 204), maybe try another simple example? 109,12,203,-5,204,-5,99 Simply appends the given input and outputs it.

mpcjanssen 2019-12-09T09:55:39.477700Z

so you take the immediate value and add it to base for 203

mpcjanssen 2019-12-09T09:57:34.479200Z

yep thats it

mpcjanssen 2019-12-09T09:58:25.481Z

same change is needed for all storing ops

gbouvier 2019-12-09T10:00:56.482900Z

👍 Nice, I'm not sure how to think about this. Up until today, I was treating outputs as a special case and always using the immediate mode. Today, after refactoring, I realized I could handle my args as always pointing to a position and just pointing to the argument position in the case of immediate mode. Makes it so I can handle all the args generally, and operands (as opposed to outputs) are just fed through an additional (nth) right before they're needed, but for an output, they're already representing the positional value.

mpcjanssen 2019-12-09T10:01:49.483700Z

yes! part 1 done

🎉 1
mpcjanssen 2019-12-09T10:06:15.485200Z

the target adress behavior has been a source of pain in all intcode puzzles

mpcjanssen 2019-12-09T10:06:57.485800Z

part 2 is trivial after part 1

gbouvier 2019-12-09T10:07:44.486300Z

Yeah, I wonder if it's even possible to finish part 1 and not be able to complete part 2.

2019-12-09T10:18:27.486500Z

😂 I ran to work after completing part 1. I couldn’t complete part 2 so far 😂

gbouvier 2019-12-09T10:22:59.486800Z

I guess the tests in part 1 aren't adequate then.

2019-12-09T10:25:44.487Z

I meant that I literally saw the message about getting the star and left without even reading part 2 😉 I did that on my way and will have to wait for tonight to get back to my code

gbouvier 2019-12-09T10:27:20.487300Z

Ahh, that makes sense. In this case at least, it shouldn't be a lot of work for you to finish part 2.

2019-12-09T10:28:05.487500Z

😁

2019-12-09T10:29:32.487700Z

sounds like using different input and go get it… a shame not to have done it directly. 🤷:skin-tone-2: but I was already late for real life 😉 And I have seen problems before that also seemed to only need a different input but then created out of memory errors and such… (see e.g. 2016, day 16)

tws 2019-12-09T13:05:35.489900Z

I don’t understand what makes day 7 p2 halt

tws 2019-12-09T13:05:57.490200Z

why not feedback forever? Or do the outputs start to decrease?

2019-12-09T13:08:53.490300Z

I had the same problem

2019-12-09T13:09:34.490500Z

try this thread, if you want the same explanation I got: https://clojurians.slack.com/archives/C0GLTDB2T/p1575701095380500

tws 2019-12-09T13:12:20.490800Z

got it, thanks

2019-12-09T13:13:16.491Z

:thumbsup::skin-tone-2: you’re welcome. This made a solid knot in my brain 😂

tws 2019-12-09T13:38:50.491200Z

feels like the job - spend more time trying to understand requirements than writing code

2019-12-09T13:48:22.491400Z

😂

Average-user 2019-12-09T14:09:55.491600Z

It happened the same to me, I was forgeting to implement mode 2 for write arguments of opcodes 1 2 3 7 8

2019-12-09T14:28:24.491800Z

Got the same problem. :D @tws Is it ok now ?

2019-12-09T15:21:02.493400Z

ya’ll

2019-12-09T15:21:05.493600Z

clojure is so great

2019-12-09T15:21:30.494Z

we it said we needed non-contiguous memory

2019-12-09T15:21:55.494500Z

instead of a vector for state, you can pass in a map

2019-12-09T15:21:58.494700Z

done

2019-12-09T15:22:48.495300Z

(I was using subvec, so I did have to change to map over a range. But everything else Just Worked™.)

mpcjanssen 2019-12-09T15:48:19.495500Z

How did accessing elements not in the map just work and give 0?

2019-12-09T16:13:48.495700Z

get/get-in allow for a default value if an entry in a map doesn’t get found (see <https://clojuredocs.org/clojure.core/get-in> for reference)

💯 1
mpcjanssen 2019-12-09T16:16:46.496Z

I switched from vector to map and indeed I had to add a default 0 to all direct map access. I was just curious if I missed something like a default non existing value

fellshard 2019-12-09T16:26:58.496200Z

In the Reddit thread, he said it should be a freebie, but part 2 might find some wrinkles in your implementation.

2019-12-09T16:28:10.496500Z

No, but it was trivial. I shadowed get in my let binding.

2019-12-09T16:36:32.497300Z

Gotta catch up with all of you, here’s my day 8 https://gist.github.com/roman01la/7e505fa83e74b4730d74f096f6172fff

James Adam 2019-12-09T16:58:36.499100Z

@potetm I cheated -- I still passed in a vector, but did a (into [] (concat program (take 999 (cycle 0)))) and just kept increasing the amount of 0s I was adding to the "memory" vector until it passed. I did this because I'm lazy and I hate the vm problems in AOC.

misha 2019-12-09T17:04:59.000400Z

so "memory starting at 0" is not a looping indexes around, zzz

2019-12-09T17:11:00.000900Z

I just assumed it was gonna blow out any arbitrary pre-fill

misha 2019-12-09T17:14:07.001900Z

I tried wrap first: (- idx (count mem)), but then just moved on with my life :kappa:

2019-12-09T17:52:03.002100Z

This has been painful even on Day 5, but destinations are always to be treated as values!

2019-12-09T18:54:16.002300Z

when all the amplifiers have halted the circuit is halted?

2019-12-09T19:21:46.003800Z

The broken test outputs from the BOOST program were super helpful to narrow things down.

☝️ 1
rjray 2019-12-09T19:30:37.004Z

No kidding.

rjray 2019-12-09T19:30:55.004500Z

FINALLY have this done. All I will say, is that part 2 is trivial once you have part 1.

2019-12-09T19:33:28.004600Z

yepp

2019-12-09T20:05:54.006100Z

My day 9: https://github.com/chrisblom/advent-of-code/blob/master/src/adventofcode/2019/intcode.clj#L80 I also forgot to set the mode for the write parameter, too bad the tests did not detect it.

pesterhazy 2019-12-09T20:20:13.006300Z

same problem with relative writes for me - Eric could have mentioned that in the description

pesterhazy 2019-12-09T20:20:47.006500Z

I assumed that because mode 1 doesn't exist for writing, only mode 0 does - but that's not the case

pesterhazy 2019-12-09T20:21:21.006700Z

defensive coding (checking that the mode is well known in the code for set) would have caught this

pesterhazy 2019-12-09T20:22:30.006900Z

it's interesting - type checks or unit tests wouldn't really have helped here, although a simple (asset (= mode 0)) would have

fellshard 2019-12-09T20:24:32.007100Z

Yeah, I had to run back to day 5 to check the wording of how output addresses are handled; he didn't say 'they are always positional mode', but rather 'they are never immediate mode'

pesterhazy 2019-12-09T20:24:56.007700Z

My day 9, if anyone is curious in a Typescript solution: https://github.com/pesterhazy/advent2019/blob/master/typescript/src/puzzle09.ts

pesterhazy 2019-12-09T20:25:30.008300Z

Modern Javascript shines here, with bigints and generators

pesterhazy 2019-12-09T20:25:57.008900Z

(By choosing JS/Typescript I'm getting out of my comfort zone deliberately)

pesterhazy 2019-12-09T20:26:35.009100Z

You could say it's a trap 🙂

tws 2019-12-09T21:09:59.009700Z

haven’t tried yet, day job. I think it’s more about blocking when you’re expecting input, writing out current state, then resuming when you have some. I’m not going to do channels, I think it should work.

tws 2019-12-09T21:10:19.009900Z

but honestly, I missed that from the requirements wholly

2019-12-09T21:14:58.010100Z

You're on the right way, but be careful to meaning you put behind "blocking". For the requirements, in my first (and probably second and third ^^) read, I miss this sentence. > If the amplifier has not yet received an input signal, it waits until one arrives.

mpcjanssen 2019-12-09T22:32:28.010300Z

Ah smart

erwinrooijakkers 2019-12-09T23:21:22.010500Z

Thanks

erwinrooijakkers 2019-12-09T23:24:32.012400Z

With help from the hints here (thanks) about read and write mode I managed to finish: https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day9.clj Could be shortened if numbers could be turned into IFns that look themselves up in a map, but I read that that’s not possible in Clojure (but that it is in cljs)

erwinrooijakkers 2019-12-09T23:28:19.013200Z

Visualisation from reddit yesterday: https://preview.redd.it/d2xityozj8341.gif?width=904&amp;format=mp4&amp;s=c97ef3e9af23ae0ed5b6a962322c59ef4c41477a