This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-14
Channels
- # adventofcode (62)
- # beginners (78)
- # boot (26)
- # boot-dev (9)
- # cider (73)
- # cljs-dev (33)
- # cljsrn (36)
- # clojure (159)
- # clojure-android (1)
- # clojure-austin (1)
- # clojure-greece (79)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-russia (11)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (107)
- # core-async (22)
- # core-logic (12)
- # cursive (16)
- # datomic (13)
- # devcards (5)
- # duct (36)
- # emacs (4)
- # figwheel (3)
- # fulcro (107)
- # graphql (171)
- # hoplon (27)
- # instaparse (24)
- # jobs-discuss (34)
- # juxt (3)
- # lein-figwheel (1)
- # leiningen (8)
- # lumo (11)
- # off-topic (9)
- # onyx (79)
- # parinfer (1)
- # pedestal (75)
- # re-frame (27)
- # rum (1)
- # shadow-cljs (11)
- # spacemacs (20)
- # specter (17)
- # unrepl (96)
yeah, I had to go back to my day10 solution to improve its performance
transients!
Am I missing something? I think (row "flqrgnkx" 0)
should return 11110000
although their example grid shows different?
Horrible: I guessed the right answer for part 2 by offsetting it to the example and the wrong output for that one…
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day14.clj
@bhauman Funny, mine is faster for part 2 while I borrowed only your groups function 🙂
I'm pretty sure the fact that you are using .charAt
along with a tuned neighbors
function is whats making the difference
@bhauman why is there an 8 here instead of 4? https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day14.clj#L14
I bought it just before the new Macbook Pros came out… I wanted to wait, but hell, I just needed one right then
Anyway, thanks you for letting me borrow your groups function. I put the credits in the code 😉
with
(transduce
(comp
(map #(Integer/parseInt (str %) 16))
(map #(Integer/toBinaryString %))
(map #(format "%4s" %)))
str
kh)
I get marginal speedupmaybe (transduce ... str ..)
isn’t that optimal, I don’t know it will still use StringBuilders that way
Gotcha:
boot.user=> (time (do (reduce str (range 100000)) nil))
“Elapsed time: 14011.548079 msecs”
nil
boot.user=> (time (do (apply str (range 100000)) nil))
“Elapsed time: 6.564031 msecs”
nil
Day 14: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_14.cljc
Actually the string thing is not where the most time is spent in my code. It’s the knot hash itself which should be optimized.
But for the future it may be good to know:
boot.user=> (time (do (transduce (map identity) str (range 100000)) nil))
“Elapsed time: 13888.143336 msecs”
nil
boot.user=> (time (do (apply str (range 100000)) nil))
“Elapsed time: 6.55865 msecs”
It looks like @cgrand might be joining the fun. He posted yesterday's https://github.com/cgrand/advent2017/blob/master/src/advent2017/day13.clj
I was miffed that there is a cljs.core/bit-count
but in Clojure you need to do interop.
(time (do (transduce (map identity) str (range 100000)) nil))
"Elapsed time: 16865.420273 msecs"
(time (do (apply str (range 100000)) nil))
"Elapsed time: 14.711439 msecs"
(time (do (transduce (map identity) net.cgrand.xforms.rfs/str (range 100000)) nil))
"Elapsed time: 7.697859 msecs"
@thegeez expected that to be in there… I might revert my code to the transducer now! 🙂
hmmmmm i wonder if Long/bitCount
would fail if you happened to get a negative hash number?
@bhauman I suppose for this particular problem it ended up being OK because you permute (range 256)
and I have it doing bit-xor
chunks 16 at a time. In other words, things stay positive because they fit in long
An example:
user=> (advent-2017.day-10/knot-hash-decimal "adfdf")
[72 206 34 163 109 167 172 101 51 5 47 187 155 72 76 57]