This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Today was easy. I think the ethical thing of them to do, to have a nice Christmas day with the family 😉
i skipped parsing of input today, not a part i really enjoy, and very simple to convert to a clojure structure in an editor using multicursors 🙂
my code, nothing very clever: https://github.com/ihabunek/aoc2017/blob/master/src/aoc2017/day25.clj
@ihabunek very similar to mine 🙂 https://github.com/borkdude/aoc2017/blob/master/src/day25.clj
I’ve read somewhere in an article that all puzzles should run below or around 10s on 10year old hardware
And we can get to that speed, @mfikes and I got to world domination on day 5: https://github.com/borkdude/aoc2017/blob/master/src/day05.clj#L115
Yes, loop recur is somewhat faster than iterate I think, because it doesn’t construct a seq
(time (loop [counter 0] (if (= counter 100000000) counter (recur (inc counter))))) ;; 33ms (time (nth (iterate inc 0) 100000000)) ;; 2797 ms
Not sure if there is anything better with transducers + iterate to make the overhead smaller.
(time (transduce (drop 100000000) (fn ( nil) ([acc] acc) ([acc n] (reduced (or acc n)))) (iterate inc 0))) ;; 1915ms
@borkdude in newer versions of Clojure (1.8+ IIRC) that can be done with (range) instead of (iterate). If the input args are longs there's a fastpath in Clojure that produces a reducible that stores the state as unboxed longs.
The input arg for my typical use aren’t ints, I just need the behavior of iterate to produce successive game states
On my hardware, the
iterate above takes 2071 ms in the
clj REPL. With the update to
iterate in ClojureScript master, in Planck this same form takes 1779 ms.
Interestingly in the node REPL the first execution takes around 750 ms, and subsequent ones drop back down to 1800 ms.