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
uneman 2019-12-16T05:47:26.042100Z

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

rjray 2019-12-16T06:36:35.042600Z

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

rjray 2019-12-16T06:36:55.043100Z

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

misha 2019-12-16T06:38:20.043400Z

I think p2 is about this

rjray 2019-12-16T07:09:33.044600Z

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.

mpcjanssen 2019-12-16T09:43:22.048400Z

Any hints?

rjray 2019-12-16T18:07:40.056200Z

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.

misha 2019-12-16T19:29:13.059300Z

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.

fellshard 2019-12-16T07:48:30.044900Z

Day 15 Viz - Exploration Phase http://quil.info/sketches/show/f4932cfba1834c15f9778ccbfa2f6e31cef89ebef27e45b16c3663cf6015bee8

erwinrooijakkers 2019-12-16T09:33:26.046200Z

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

erwinrooijakkers 2019-12-16T09:33:34.046600Z

This works on example first input

erwinrooijakkers 2019-12-16T09:33:39.046800Z

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

erwinrooijakkers 2019-12-16T09:33:46.047Z

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

erwinrooijakkers 2019-12-16T09:34:09.047400Z

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

erwinrooijakkers 2019-12-16T09:34:12.047600Z

Any suggestions?

erwinrooijakkers 2019-12-16T09:37:22.047800Z

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

mpcjanssen 2019-12-16T09:43:22.048400Z

Any hints?

yuhan 2019-12-16T11:29:15.048800Z

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

yuhan 2019-12-16T12:30:11.050900Z

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

yuhan 2019-12-16T12:34:00.054100Z

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

misha 2019-12-16T12:44:46.055200Z

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

rjray 2019-12-16T18:07:40.056200Z

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.

2019-12-16T18:21:02.057300Z

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

2019-12-16T18:22:22.058100Z

If only it was mod 10, it would be easier

2
mpcjanssen 2019-12-16T19:00:40.059100Z

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

misha 2019-12-16T19:29:13.059300Z

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.

fellshard 2019-12-16T20:30:04.060100Z

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

mpcjanssen 2019-12-16T20:46:59.061600Z

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

erwinrooijakkers 2019-12-16T21:11:08.061700Z

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

baritonehands 2019-12-16T21:17:13.061900Z

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

erwinrooijakkers 2019-12-16T21:34:55.062100Z

Ah 🙂

erwinrooijakkers 2019-12-16T21:35:31.062300Z

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

erwinrooijakkers 2019-12-16T21:35:42.062500Z

For every planet indivually

erwinrooijakkers 2019-12-16T21:35:44.062700Z

I’ll try that

erwinrooijakkers 2019-12-16T21:35:59.062900Z

I use numeric-tower/abs

Mario C. 2019-12-16T23:14:47.063700Z

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

fellshard 2019-12-16T23:19:12.064Z

Some math, some creative pattern recognition.

2019-12-16T23:33:44.065600Z

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 🤓