This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Day 25: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_25.cljc
Today was easy. I think the ethical thing of them to do, to have a nice Christmas day with the family 😉
Nice t-shirt: https://teespring.com/advent-of-code-eu#pid=389&cid=100029&sid=front
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
Slightly faster:
(time
(transduce
(drop 100000000)
(fn
([] nil)
([acc] acc)
([acc n]
(reduced (or acc n))))
(iterate inc 0))) ;; 1915ms
Not sure if there is anything better with transducers + iterate to make the overhead smaller.@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 transduce
over 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.
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day25.clj
This is a type of project where Cljs really shines. The JS jits are much better at auto unboxing