This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-05
Channels
- # adventofcode (95)
- # announcements (3)
- # babashka (11)
- # beginners (39)
- # boot (19)
- # bristol-clojurians (1)
- # cider (32)
- # clj-kondo (39)
- # cljsrn (8)
- # clojure (156)
- # clojure-dev (35)
- # clojure-europe (4)
- # clojure-italy (15)
- # clojure-nl (28)
- # clojure-spec (43)
- # clojure-uk (153)
- # clojurescript (168)
- # core-async (13)
- # core-logic (11)
- # cryogen (4)
- # cursive (13)
- # datomic (26)
- # duct (3)
- # emacs (8)
- # fulcro (33)
- # garden (4)
- # graalvm (18)
- # graphql (4)
- # jobs-discuss (2)
- # kaocha (1)
- # leiningen (3)
- # malli (8)
- # off-topic (1)
- # pathom (7)
- # re-frame (21)
- # reagent (3)
- # rewrite-clj (1)
- # schema (4)
- # shadow-cljs (40)
- # sql (2)
- # uncomplicate (3)
> 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 1
s that start the number part of a larger group of 4 matching 1s?
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
I guess I reached the limit of doable on phone today.
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.
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
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.
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)
yenda, i read tests when description is unclear, so tests screwed me over even more today
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.
?
Basically, ignore the mode for that parameter - always treat the parameter's value as the address to output to.
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)))
https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2019/day05.clj#L40-L47
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.
positional: "interpret v as a pointer" intermediate: "interpret v as a value"
you can only write to a pointer, a mutable container; you cannot conceptually write to an immutable value
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
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.
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.
So a successful run of the first part should be 0 0 0 0 0 0 ... 0 0 <diagnostic code>
If something did go wrong in your implementation, you could use the output to help you pin down where it's going sideways
Visualization for day 5: http://quil.info/sketches/show/e73e5daea052772c66ae391140ede3fd1c0ff6ebe950476b8e85bb10f0769980
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.
That part wasn't the clearest stated. I only caught on because I've seen him use it before. 🙂
Today was smooth sailing, mostly reading comprehension (again in Typescript: https://github.com/pesterhazy/advent2019/blob/master/typescript/src/puzzle05.ts)
Just soldiered through on phone. Day 5 done
Tricky part was the targets are never in immediate mode part
Again the key was to make small fns
On phone? I can’t even..
I was planning to stop today
But with small enough steps it was doable
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.
That's basically what I did: https://github.com/rjray/advent-2019-clojure/blob/master/src/advent_2019/day05.clj
If we add many more instructions to this VM, though, I'll probably move the dispatch to a vector.
Already made that choice on day2 and it worked well today
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
after some cleanup it actually became quite readable [= https://github.com/uosl/advent-of-code/blob/master/src/aoc2019/05.clj
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
Thanks. Apart from those two differences (and you keeping track of input
) our solutions are pretty similar!
The drop off in completed answers for today is huge
Yea, I looked at the problem description early this morning and decided I'd tackle it after work tonight 🙂
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
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.
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
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.
Here’s my 5th day https://gist.github.com/roman01la/875d7c0c3cc8b75267730559b5d96251
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
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
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.
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
(defn total-fuel-mass [mass]
(loop [remaining mass
total 0]
(let [mass (fuel-mass remaining)]
(if (pos? mass)
(recur mass (+ total mass))
total))))
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.
I think I'm close already! But I'm missing something crucial because I'm getting an answer that is too high.
formatting looks funky here from my copy and paste but it's lined up correctly in my editor.
(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 +)))
That's basically what I did: https://github.com/rjray/advent-2019-clojure/blob/master/src/advent_2019/day05.clj
If we add many more instructions to this VM, though, I'll probably move the dispatch to a vector.
(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!)
I was getting behind, did 3,4 and 5 today: https://github.com/ChrisBlom/advent-of-code/tree/master/src/adventofcode/2019