...is today's pt2 something to do with DFT? 🤦
Part 2 definitely involves some number-theory-level stuff that I'm not getting...
Part 1 was almost trivial with Clojure's support for lazy sequences.
I think p2 is about this
Part 2 done. Found an algorithm I could adapt. Turned out to be scarily fast, much faster than the computation of part 1 had been.
Any hints?
Ugh... I thought I still had the tabs open from my searching, but I don't. And it was pretty late when I finished last night and my memory is a little hazy. I'll see if I can find the original algorithm I saw.
see how far to the right your message offset is, and think about how expanded cycled [0 1 0 -1] pattern would look like that far right into the input list.
Day 15 Viz - Exploration Phase http://quil.info/sketches/show/f4932cfba1834c15f9778ccbfa2f6e31cef89ebef27e45b16c3663cf6015bee8
I am a bit behind because of birthday parties, but cannot get day 12 to work. This is what I have now: https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day12.clj Based on reddit/r/adventofcode information I can check when first state recurs (since the problem is such that the beginning state wil recur):
(defn idx-back-to-initial-state [states]
(first
(keep-indexed
(fn [i state] (when (= state (first states)) (inc i)))
(rest states))))
(defn period [moon-name]
(->> moons
(iterate gravity)
(map (comp first (partial filter (comp #{moon-name} :name))))
idx-back-to-initial-state))
(reduce lcm (map period (range 4)))
This works on example first input
But with second input and my question input I get this exception:
1. Caused by java.lang.OutOfMemoryError
GC overhead limit exceeded
I added the flag :jvm-opts ["-Xmx8g"]
but still after about 2 hours
Any suggestions?
Oh and (iterate gravity moons)
looks like this:
({:name 0,
:positions {:x -7, :y -8, :z 0},
:velocities {:x -3, :y 1, :z 3}}
{:name 1,
:positions {:x -14, :y -8, :z 1},
:velocities {:x -1, :y 3, :z 1}}
{:name 2,
:positions {:x -14, :y -8, :z 12},
:velocities {:x 3, :y -1, :z -3}}
{:name 3,
:positions {:x -15, :y 1, :z 1},
:velocities {:x 1, :y -3, :z -1}}
...)
hint: The point of Day 12 Part 2 is for you to examine the problem more deeply and gain some insight which lets you solve it far more efficiently than brute force
solving Day 15 without any explicit backtracking was one of the most satisfying parts of doing AOC in Clojure so far :)
(bfs robot) := (apply medley/interleave-all (for [dir [1 2 3 4]] (bfs (move robot dir)))
well, at least I understand the p2 solution today, but did not quite came up with it myself :harold:
The first thing coming to mind is to diagonalise the pattern matrix, but that ‘taking the last digit’ operation makes it nonlinear…
If only it was mod 10, it would be easier
my day 16 input was changes and I lost the first star (puzzled)
Are you still logged in? Could be they found a bug in the input, or someone reported a bug in that input
yep still logged in. Anyway resubmitted part one. Now struggling with part 2
Thanks. Even more efficient than looking at the periods of the individual moons and taking the lcm?
Yeah, that was the trick suggested on Reddit. But in my case, I was using the wrong overload of Math/abs
so it was truncating the integers
Ah 🙂
I also see a suggestion to only look at periods in x y or z
For every planet indivually
I’ll try that
I use numeric-tower/abs
I feel like after Day10 all these problems require that you recognize some computer-science/math theory.
Some math, some creative pattern recognition.
Wow, finally got day 16. https://gitlab.com/dmarjenburgh/adventofcode/blob/master/src/adventofcode/year_2019.clj#L492-509 A lot of pen-and-paper and little bit of coding. How does Eric come up with these things 🤓