This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-17
Channels
- # adventofcode (23)
- # announcements (2)
- # aws (11)
- # babashka (181)
- # beginners (59)
- # chestnut (2)
- # clj-kondo (9)
- # clojure (90)
- # clojure-brasil (2)
- # clojure-europe (18)
- # clojure-italy (24)
- # clojure-nl (9)
- # clojure-spec (3)
- # clojure-uk (28)
- # clojured (4)
- # clojuredesign-podcast (3)
- # clojurescript (12)
- # community-development (49)
- # core-async (49)
- # cryogen (5)
- # cursive (16)
- # data-science (1)
- # datascript (7)
- # datomic (54)
- # defnpodcast (4)
- # events (2)
- # figwheel-main (14)
- # fulcro (139)
- # graphql (1)
- # jobs-discuss (6)
- # kaocha (1)
- # luminus (2)
- # malli (3)
- # music (1)
- # off-topic (34)
- # pathom (24)
- # re-frame (13)
- # reitit (5)
- # shadow-cljs (8)
- # test-check (6)
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
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)))
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 @U0E2P47B7 what did is what I was trying to go for
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.
but I did get few stars for previous years leaving laptop to heat up for 40+ minutes few times, yes
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.
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.