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
But I can't get the zero's repeating.
I am grasping at straws here lol
I created a function which returns three mth value of the pattern for digit m
Digit n
(defn pattern [n m]
;; (println (str n ":" m))
(let [base [0, 1, 0, -1]
idx (base (mod (quot m n) 4))]
idx))
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
the part 2 solution is not about speeding up though
😯 I think maybe I misunderstood part 2
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"?
Or does it mean run the FFT program at 100 phases. Then use that result in another 100 phase run. And repeat 1000 times?
"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.
Yea thats what I meant by speeding things up
but I did get few stars for previous years leaving laptop to heat up for 40+ minutes few times, yes :opieop:
A star is a star xD
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)))`
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)))
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.
03:30 is not "too long" :kappa:
Day 17: https://gitlab.com/dmarjenburgh/adventofcode/blob/master/src/adventofcode/year_2019.clj#L505-539
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.
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.
I implemented shortest path, but did not have time to implement path partition