Fork me on GitHub
#adventofcode
<
2019-12-17
>
Mario C.04:12:21

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.04:12:44

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

Mario C.04:12:01

I am grasping at straws here lol

namenu06:12:30

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

misha07:12:40

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

mpcjanssen08:12:01

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

mpcjanssen08:12:32

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

Mario C.17:12:20

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 @U0E2P47B7 what did is what I was trying to go for

misha18:12:36

the part 2 solution is not about speeding up though

Mario C.18:12:13

😯 I think maybe I misunderstood part 2

Mario C.18:12:43

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.18:12:33

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

misha18:12:23

"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.18:12:33

Yea thats what I meant by speeding things up

misha18:12:01

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

Mario C.18:12:41

A star is a star xD

fellshard08:12:43

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.

misha08:12:43

03:30 is not "too long" kappa

4
😂 4
rjray19:12:43

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.

rjray19:12:17

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.

misha20:12:06

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