Fork me on GitHub
#adventofcode
<
2017-12-14
>
minikomi01:12:50

Way too busy for today’s drop.. good luck folks

fellshard05:12:27

Well, well. This day's uses a couple of old friends.

dyankowsky06:12:50

yeah, I had to go back to my day10 solution to improve its performance

borkdude07:12:28

Am I missing something? I think (row "flqrgnkx" 0) should return 11110000 although their example grid shows different?

borkdude07:12:20

This works though: (= “10100000110000100000000101110000” (row “a0c2017" 0))

borkdude12:12:53

Horrible: I guessed the right answer for part 2 by offsetting it to the example and the wrong output for that one…

borkdude12:12:00

but I still have to fix the code 😛

bhauman15:12:55

thank goodness for all the perf work done on day 10

borkdude15:12:19

@bhauman Funny, mine is faster for part 2 while I borrowed only your groups function 🙂

borkdude15:12:53

my part 1 is much slower though

borkdude15:12:53

not sure if it’s my input or something in my code.. looks about the same

bhauman15:12:55

yeah get-in is killing me

borkdude15:12:06

oh day 10 optimizations, sorry I thought day 12

borkdude15:12:13

yeah, I didn’t optimize day 10

bhauman15:12:53

also my neighbors function could be improved for speed

bhauman15:12:49

I'm pretty sure the fact that you are using .charAt along with a tuned neighbors function is whats making the difference

bhauman15:12:15

for part 2

bhauman15:12:35

cl-format is killing you on part 1

bhauman15:12:49

its a dog yo

borkdude15:12:50

the type annotations didn’t matter very much though

bhauman15:12:50

also remember your hardware is showing up consistently faster than mine

bhauman15:12:03

16 numbers

borkdude15:12:05

@bhauman I’m on a Macbook Pro 15" 2015

bhauman15:12:17

well its faster than mine 🙂

borkdude15:12:05

I bought it just before the new Macbook Pros came out… I wanted to wait, but hell, I just needed one right then

bhauman15:12:55

did you figure out why I use 8 instead of 4?

borkdude15:12:04

Anyway, thanks you for letting me borrow your groups function. I put the credits in the code 😉

borkdude15:12:18

It’s one of the most awesome functions I’ve come across so far

borkdude15:12:49

no, I’d have to start up a REPL to see what’s going on

bhauman15:12:25

I'm iterating over the numbers not the hex characters

bhauman15:12:04

1 number = 2 hex chars

borkdude15:12:52

ah I see yeah

bhauman15:12:13

that probably speeds it up as well

borkdude16:12:21

with

(transduce
     (comp
      (map #(Integer/parseInt (str %) 16))
      (map #(Integer/toBinaryString %))
      (map #(format "%4s" %)))
     str
     kh)
I get marginal speedup

borkdude16:12:01

I’ll leave the optimization for when it’s really needed today

borkdude16:12:13

maybe (transduce ... str ..) isn’t that optimal, I don’t know it will still use StringBuilders that way

borkdude16:12:04

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

borkdude16:12:12

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.

borkdude16:12:29

mfikes: great job. Also revisited two previous days 🙂

borkdude16:12:44

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”

mfikes16:12:45

It looks like @cgrand might be joining the fun. He posted yesterday's https://github.com/cgrand/advent2017/blob/master/src/advent2017/day13.clj

mfikes16:12:09

I was miffed that there is a cljs.core/bit-count but in Clojure you need to do interop.

thegeez16:12:13

@borkdude

(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"

borkdude16:12:50

@thegeez expected that to be in there… I might revert my code to the transducer now! 🙂

bhauman18:12:25

hmmmmm i wonder if Long/bitCount would fail if you happened to get a negative hash number?

bhauman18:12:26

and congrats on what looks like a very speedy implementation

mfikes18:12:48

@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

mfikes18:12:22

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]

mfikes18:12:49

(I cheated a bit by having my day 10 solution provide the underlying vector of numbers.)

bhauman18:12:14

as did I good sir, as did I