Fork me on GitHub
#adventofcode
<
2019-12-16
>
namenu05:12:26

...is today's pt2 something to do with DFT? facepalm

rjray06:12:35

Part 2 definitely involves some number-theory-level stuff that I'm not getting...

rjray06:12:55

Part 1 was almost trivial with Clojure's support for lazy sequences.

misha06:12:20

I think p2 is about this

rjray07:12:33

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.

rjray18:12:40

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.

misha19:12:13

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.

erwinrooijakkers09:12:26

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))) 

erwinrooijakkers09:12:34

This works on example first input

erwinrooijakkers09:12:39

But with second input and my question input I get this exception:

erwinrooijakkers09:12:46

1. Caused by java.lang.OutOfMemoryError
GC overhead limit exceeded

erwinrooijakkers09:12:09

I added the flag :jvm-opts ["-Xmx8g"] but still after about 2 hours

erwinrooijakkers09:12:12

Any suggestions?

yuhan11:12:15

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

erwinrooijakkers21:12:08

Thanks. Even more efficient than looking at the periods of the individual moons and taking the lcm?

baritonehands21:12:13

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

erwinrooijakkers21:12:31

I also see a suggestion to only look at periods in x y or z

erwinrooijakkers21:12:42

For every planet indivually

erwinrooijakkers21:12:59

I use numeric-tower/abs

erwinrooijakkers09:12:22

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}}
 ...)

yuhan12:12:11

solving Day 15 without any explicit backtracking was one of the most satisfying parts of doing AOC in Clojure so far :)

yuhan12:12:00

(bfs robot) := (apply medley/interleave-all (for [dir [1 2 3 4]] (bfs (move robot dir)))

misha12:12:46

well, at least I understand the p2 solution today, but did not quite came up with it myself harold

dmarjenburgh18:12:02

The first thing coming to mind is to diagonalise the pattern matrix, but that ‘taking the last digit’ operation makes it nonlinear…

dmarjenburgh18:12:22

If only it was mod 10, it would be easier

trollface 8
mpcjanssen19:12:40

my day 16 input was changes and I lost the first star (puzzled)

fellshard20:12:04

Are you still logged in? Could be they found a bug in the input, or someone reported a bug in that input

mpcjanssen20:12:59

yep still logged in. Anyway resubmitted part one. Now struggling with part 2

Mario C.23:12:47

I feel like after Day10 all these problems require that you recognize some computer-science/math theory.

fellshard23:12:12

Some math, some creative pattern recognition.

dmarjenburgh23:12:44

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 🤓