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
Mario C. 2019-12-17T04:35:21.066800Z

I am working on Day 16 right now and created a function that essentially returns the repeating patterns.

(defn sn
  [a n]
  (let [f (/ (* n Math/PI) (inc a))
        r (Math/sin f)]
    (Math/round r)))

(doseq [n (range 0 10)]
  (println (str (inc n) ": ")  (sn 1 n))) => 0 1 0 -1 0 1 0 -1 ... etc

Mario C. 2019-12-17T04:35:44.067200Z

But I can't get the zero's repeating.

Mario C. 2019-12-17T04:36:01.067500Z

I am grasping at straws here lol

mpcjanssen 2019-12-17T08:10:01.068Z

I created a function which returns three mth value of the pattern for digit m

mpcjanssen 2019-12-17T08:10:10.068200Z

Digit n

mpcjanssen 2019-12-17T08:11:32.068400Z

(defn pattern [n m]
  ;;  (println (str n ":" m))
 (let [base [0, 1, 0, -1]
       idx  (base (mod (quot  m n) 4))]
  idx))

Mario C. 2019-12-17T17:31:20.071600Z

I originally did it with the cycle mapcat and repeat (Such constructs is why I love clojure lol) but I figured to speed stuff up for part two I need to create some sine function that I can pass in parameters to change the freq and then a nth digit to pull from that. If that makes sense. I think @mpcjanssen what did is what I was trying to go for

misha 2019-12-17T18:01:36.071800Z

the part 2 solution is not about speeding up though

Mario C. 2019-12-17T18:23:13.072Z

😯 I think maybe I misunderstood part 2

Mario C. 2019-12-17T18:26:43.072200Z

When it says the real input signal is the signal repeated 10000 times does it mean that if my input was "abcd" and it was repeated 3 times then my real signal would be "abcdabcdabcd"?

Mario C. 2019-12-17T18:27:33.072400Z

Or does it mean run the FFT program at 100 phases. Then use that result in another 100 phase run. And repeat 1000 times?

misha 2019-12-17T18:31:23.072600Z

"abcd" -> "abcdabcdabcd", yes but usually in late adventofcode puzzles part 2 uses repeated 10000 times or similar exaggeration to hint that solution is not to brute force it. Especially if you are not solving using c, rust, etc.

Mario C. 2019-12-17T18:32:33.072800Z

Yea thats what I meant by speeding things up

misha 2019-12-17T18:33:01.073100Z

but I did get few stars for previous years leaving laptop to heat up for 40+ minutes few times, yes :opieop:

Mario C. 2019-12-17T18:33:41.073300Z

A star is a star xD

uneman 2019-12-17T06:34:30.067600Z

actually i didn't go with trigonometry. but here's my sequence function. `(defn pattern [phase] (->> (mapcat #(repeat phase %) [0 1 0 -1]) (cycle) (drop 1)))`

misha 2019-12-17T07:20:40.067800Z

you can define all (∞) patterns once:

(defn pattern [idx]
  (->> [0 1 0 -1]
    (mapcat (partial repeat (inc idx)))
    (cycle)
    (rest)))

(def patterns (map pattern (range)))

fellshard 2019-12-17T08:26:43.069600Z

Took me way too long today. Got fixated on an incorrect set of core instructions, had to restart from the ground-up with different tactics to shake that faulty assumption.

misha 2019-12-17T08:34:43.070200Z

03:30 is not "too long" :kappa:

😂 1
1
rjray 2019-12-17T19:02:43.074300Z

Just finished part 2. Like you, I "encoded" things by hand ahead of time. I'm def gonna go back to this when I have time and try to derive an algorithm for that.

rjray 2019-12-17T19:10:17.074900Z

From looking at your code, I clearly need to learn how to use channels. My mechanism for I/O is... clunky to say the least.

misha 2019-12-17T20:34:06.075500Z

I implemented shortest path, but did not have time to implement path partition