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
dpsutton 2019-12-05T03:36:27.261400Z

typos and misreading just murdered me on part 1 of day 4

dpsutton 2019-12-05T03:41:09.262900Z

> 111122 meets the criteria (even though 1 is repeated more than twice, it still contains a double 22). i can't fathom how this meets the rule? "the two adjacent matching digits are not part of a larger group of matching digits". Aren't the two adjacent 1s that start the number part of a larger group of 4 matching 1s?

fellshard 2019-12-05T03:48:41.263300Z

There just has to be a pair in the number that is not part of a larger group

fellshard 2019-12-05T03:49:08.264200Z

It's 'exists', not 'all'

fellshard 2019-12-05T03:49:15.264400Z

The 1s do not satisfy the condition, but the pair of 2s do

dpsutton 2019-12-05T03:55:14.265Z

The two adjacent 1s are part of a larger group of 1s

dpsutton 2019-12-05T03:55:36.265200Z

Oh I see

dpsutton 2019-12-05T03:55:39.265400Z

Ugh

kenj 2019-12-05T03:58:07.266400Z

That through me off as well for a good while

dpsutton 2019-12-05T04:52:30.267Z

https://github.com/dpsutton/advent/blob/master/2019/src/advent/04.clj did it in core.logic. would love people more familiar with it to critique. i know there has to be some more clever bits

šŸ¦œ 1
fingertoe 2019-12-05T05:24:54.270500Z

Well, the new one is going to take some studyā€¦ šŸ˜‰

kenj 2019-12-05T05:34:34.271900Z

Iā€™m really digging the build-a-cpu aspect of it

mpcjanssen 2019-12-05T05:37:25.273Z

I guess I reached the limit of doable on phone today.

misha 2019-12-05T06:50:50.273700Z

whoever complained about puzzle description yesterday, how do you like it now? lol

misha 2019-12-05T07:04:56.274400Z

especially the compare it to the value 8 bit. wtf is that about?

misha 2019-12-05T08:00:42.283900Z

that is some unnecessary complication/indirection for test cases, which is useless, unless your implementation fits. instead of just "this (much shorter) input returns x", which is implementation agnostic, although more blackboxy

fellshard 2019-12-05T08:16:08.285200Z

Sure, he could have made some shorter. You can always test each instruction in isolation if you want. He's giving slightly larger test cases that make for 'full programs', though, from input to output; call them integration tests.

yenda 2019-12-05T08:57:21.288200Z

I didn't even read the tests lol, just added the 4 new instructions

yenda 2019-12-05T08:57:42.288600Z

there was too much text today šŸ˜„

fellshard 2019-12-05T09:09:04.291700Z

You ain't seen nothin' until you've solved 2018-15. https://adventofcode.com/2018/day/15 (That problem gained quite a bit of infamy for being very fiddly to solve, and taking a whole bunch of space to thoroughly explain to boot)

misha 2019-12-05T10:17:06.299700Z

I think I just printed output to figure it out, then

misha 2019-12-05T10:18:15.299900Z

yenda, i read tests when description is unclear, so tests screwed me over even more today :opieop:

misha 2019-12-05T07:09:33.274900Z

and shouldn't this Parameters that an instruction writes to will never be in immediate mode. be Parameters that an instruction writes to will never be in position mode.?

fellshard 2019-12-05T08:20:09.285400Z

Correct, that's position mode by definition.

fellshard 2019-12-05T08:20:32.285600Z

position mode = 'the value in the cell is an address' (whether for input or output) immediate mode = 'the value in the cell is a concrete value' (for input only) You're assuming 'position mode' also means 'get the value from the addressed cell and use that as the address to output to', which is stretching the definition of 'position mode' one step too far. The mode only tells you how the parameter's value is to be interpreted: the action you take with the parameter depends entirely on the command's context. For positional inputs, you read from the address. For positional outputs, you write to the address.

misha 2019-12-05T08:28:30.286100Z

all I can say ā€“ I don't interpret the description as unambiguously as you do.

misha 2019-12-05T08:31:22.286300Z

(given context, which is load of text from both day 5 and day 2)

pesterhazy 2019-12-05T08:36:12.286500Z

positional: "interpret v as a pointer" intermediate: "interpret v as a value"

pesterhazy 2019-12-05T08:37:03.286700Z

you can only write to a pointer, a mutable container; you cannot conceptually write to an immutable value

genmeblog 2019-12-05T07:25:26.276Z

It should be in position mode. It writes to the address. So it's ok.

misha 2019-12-05T08:07:18.284200Z

yes, but the value of address to write to is always in immediate mode (for my input anyway). maybe I am confusing myself by thinking about it as: in immediate: (f x) => (f x) in position: (f x) => (f (get state x)) but in my solution, I never do (update state (get state x) ...), instead all of instruction do: (update state x ...) , which is pretty immediate to me

misha 2019-12-05T08:07:56.284400Z

(where state is a mutable puzzle-input vector)

genmeblog 2019-12-05T08:45:20.287600Z

from this perspective, yes, I have to agree.

genmeblog 2019-12-05T07:25:52.276500Z

I don't get this sentence: Non-zero outputs mean that a function is not working correctly; check the instructions that were run before the output instruction to see which one failed.

genmeblog 2019-12-05T07:26:18.277Z

What the 'check' means here?

genmeblog 2019-12-05T07:27:11.278200Z

And how to make to get 0's for all test outputs?

genmeblog 2019-12-05T07:30:31.278300Z

I can't find it in the text... (in part 1)

fellshard 2019-12-05T07:34:56.278900Z

Similar to what he made for the Synacor challenge

fellshard 2019-12-05T07:35:30.279700Z

tl;dr the program's first section checks for specific bugs in your implementation. For each of those tests, if it passes, it spits out a 0 in the output.

fellshard 2019-12-05T07:35:50.280300Z

So a successful run of the first part should be 0 0 0 0 0 0 ... 0 0 <diagnostic code>

āž• 1
fellshard 2019-12-05T07:36:16.280900Z

If something did go wrong in your implementation, you could use the output to help you pin down where it's going sideways

fellshard 2019-12-05T07:36:22.281100Z

But it'd take some doing

fellshard 2019-12-05T07:36:29.281300Z

Visualization for day 5: http://quil.info/sketches/show/e73e5daea052772c66ae391140ede3fd1c0ff6ebe950476b8e85bb10f0769980

ā¤ļø 1
genmeblog 2019-12-05T07:39:58.282300Z

Aaah... I understood this checks provided code not my implementation. Clear now.

fellshard 2019-12-05T07:44:21.282400Z

Basically, ignore the mode for that parameter - always treat the parameter's value as the address to output to.

fellshard 2019-12-05T07:45:34.282600Z

Those are sample programs, as he notes. You can try running them / stepping through them to get the behaviour he says it will have (in this case, comparing numbers to 8 in various ways). Use them as test cases for your implementation before trying to run your full program.

Jett Durham 2019-12-05T07:51:19.282800Z

Yeah, this confused me too at first. Made me think we might have to modify the instructions in our code! šŸ˜… To me, it seems unlikely that youā€™d actually have a solution that yields non-zero intermediate results and actually executes all the way to the terminating opcode.

misha 2019-12-05T07:56:44.283100Z

the thing is, my code works only for opposite: when it is literal v :

1 (recur idx* output (assoc state c (+ A B)))
instead of
1 (recur idx* output (assoc state (state c) (+ A B)))

misha 2019-12-05T07:58:17.283700Z

I lost like 40 minutes chasing this

fellshard 2019-12-05T08:08:44.285100Z

That part wasn't the clearest stated. I only caught on because I've seen him use it before. šŸ™‚

pesterhazy 2019-12-05T08:38:32.287400Z

Today was smooth sailing, mostly reading comprehension (again in Typescript: https://github.com/pesterhazy/advent2019/blob/master/typescript/src/puzzle05.ts)

mpcjanssen 2019-12-05T08:58:16.289700Z

Just soldiered through on phone. Day 5 done

mpcjanssen 2019-12-05T08:59:26.290500Z

Tricky part was the targets are never in immediate mode part

mpcjanssen 2019-12-05T09:02:35.291100Z

Again the key was to make small fns

pesterhazy 2019-12-05T09:03:52.291600Z

On phone? I canā€™t even..

mpcjanssen 2019-12-05T09:18:00.292300Z

I was planning to stop today

mpcjanssen 2019-12-05T09:18:22.292800Z

But with small enough steps it was doable

mchampine 2019-12-05T09:33:28.296700Z

Oof. That was rough. Completed Day 5, but my code is too ugly to share. My ā€œprogram stepā€ function consisted mostly of ā€œcase opcodeā€ statements to update the program and calculate the next instruction offset. I think if I refactored it, Iā€™d have a single function per opcode that would return the altered program and next program counter.

mpcjanssen 2019-12-05T09:45:27.298Z

I pass around a state map with mem, input, output, ip and halted keys.

ā˜ļø 1
mpcjanssen 2019-12-05T09:46:23.298800Z

So the opcode handlers can update the ip.

šŸ‘ 2
mpcjanssen 2019-12-05T09:46:52.299500Z

Already made that choice on day2 and it worked well today

2019-12-05T11:36:47.301200Z

Hereā€™s my take. Rather stateful code :man-gesturing-no::skin-tone-3: https://gitlab.com/dmarjenburgh/adventofcode/blob/master/src/adventofcode/year_2019.clj#L80-121

uosl 2019-12-05T12:25:27.301700Z

after some cleanup it actually became quite readable [= https://github.com/uosl/advent-of-code/blob/master/src/aoc2019/05.clj

šŸ‘ 1
mpcjanssen 2019-12-05T15:22:32.302500Z

The drop off in completed answers for today is huge

James Adam 2019-12-05T16:08:14.303300Z

Yea, I looked at the problem description early this morning and decided I'd tackle it after work tonight šŸ™‚

Mario C. 2019-12-05T16:45:38.305300Z

Day 5 description wasn't bad. I had to rewrite the intcode program though. Didn't like my day 2 solution. Day 5 part 2 was easy so long as what you wrote for part 1 was 'extendable' for a lack of a better term

Mario C. 2019-12-05T16:47:57.306400Z

Most functions were repeated code. So I could have probably had a wrapper that passed in the operation function while keeping the rest the same.

Mario C. 2019-12-05T16:49:35.307300Z

Day5 problem reminds me of my class on automata in college. Where you create DFA's and NFA's and there was the one where you have a tape. and you can move left or right

fellshard 2019-12-05T16:52:39.308300Z

Yeah, mostly because the data here is sitting in the same space as the instructions, and under theory he could build programs that mutate their own code on the fly.

Mario C. 2019-12-05T16:53:16.308500Z

turing machine

jrwdunham 2019-12-05T18:11:18.308600Z

Nice! I like the use of reduce and the (format "%04d" code) to unify the calculation of the positional vs. immediate values. I used a recursive strategy: https://github.com/jrwdunham/aoc2019/blob/master/src/dec05/core.clj#L19-L60

uosl 2019-12-05T19:21:56.308900Z

Thanks. Apart from those two differences (and you keeping track of input) our solutions are pretty similar!

2019-12-05T20:12:15.309300Z

Hereā€™s my 5th day https://gist.github.com/roman01la/875d7c0c3cc8b75267730559b5d96251

2019-12-05T20:19:27.312600Z

The part about always treating write location as a pointer instead of a value could be indeed confusing from implementation standpoint. Here https://gist.github.com/roman01la/875d7c0c3cc8b75267730559b5d96251#file-day5-clj-L9-L10 in writable instructions 1, 2, 3, 7 and 8 Iā€™m treating location as a value (ā€œimmediateā€ mode or 1) because it allows to keep parameter interpretation code simpler https://gist.github.com/roman01la/875d7c0c3cc8b75267730559b5d96251#file-day5-clj-L30-L35

2019-12-05T20:26:19.315400Z

my understanding is that you want to interpret write location as a value instead of a pointer, because the value is used to assoc something onto memory object, otherwise youā€™d first have to retrieve the value of the pointer and then use that value to assoc onto the memory, which is incorrect

fellshard 2019-12-05T20:57:23.316500Z

Yeah, your first instinct is to use the same logic as you would for position-mode input, but that's inevitably not right. I did the same at first, then realized I needed to just excise output parameters entirely and not pass them through the mode filter.

Chase 2019-12-05T21:32:46.318100Z

Can someone help me refactor this function from day 1 into using reduce or something more idiomatic? I still can't break myself off of immediately going to loop/recur

Chase 2019-12-05T21:32:59.318200Z

(defn total-fuel-mass [mass]                                                                                         
  (loop [remaining mass                                                                                              
         total 0]                                                                                                    
    (let [mass (fuel-mass remaining)]                                                                                
      (if (pos? mass)                                                                                                
        (recur mass (+ total mass))                                                                                  
        total))))

fellshard 2019-12-05T21:34:42.318500Z

I'd recommend looking into iterate. When there isn't an explicit sequence to reduce over, and when creating one doesn't make sense either, iterate gives similar mechanics. I use it a lot in AoC, where many problems are run until you reach a fixed point.

Chase 2019-12-05T21:38:54.318700Z

Will do! Thanks

Chase 2019-12-05T21:46:44.318900Z

I think I'm close already! But I'm missing something crucial because I'm getting an answer that is too high.

Chase 2019-12-05T21:46:56.319100Z

(defn total-fuel-mass [mass]                                                                                         
   (reduce + (take-while pos? (iterate fuel-mass mass)))) 

Chase 2019-12-05T21:48:19.319300Z

formatting looks funky here from my copy and paste but it's lined up correctly in my editor.

tws 2019-12-05T21:48:43.319500Z

skip the first element

tws 2019-12-05T21:49:39.319700Z

(defn total-fuel
 Ā "Return the fuel units required to launch a module of given `mass`,
 Ā including the mass of the fuel carried."
 Ā [mass]
 Ā (->> mass
 Ā  Ā  Ā  (iterate mass->fuel)
 Ā  Ā  Ā  rest
 Ā  Ā  Ā  (take-while pos?)
 Ā  Ā  Ā  (reduce +)))

tws 2019-12-05T21:50:18.319900Z

first run through iterate is the mass of the ship, which you donā€™t need

Chase 2019-12-05T21:50:36.320100Z

ahhh! I should have spotted that when I was exploring it in the repl.

Chase 2019-12-05T21:50:46.320300Z

thanks folks!

rjray 2019-12-05T22:01:27.322700Z

(Funny side-note: I mis-read the bit about only being allowed one private leaderboard, to mean that I could only BE on one private leaderboard at a time. So I hadn't joined the channel's leaderboard as I was already on a private one for fellow AoC enthusiasts within my company. Just joined, and thrilled to see I'm in 3rd place!)

2019-12-05T23:05:49.323400Z

I was getting behind, did 3,4 and 5 today: https://github.com/ChrisBlom/advent-of-code/tree/master/src/adventofcode/2019