adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
2017-12-14T01:47:50.000226Z

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

fellshard 2017-12-14T05:45:27.000093Z

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

dyankowsky 2017-12-14T06:13:50.000016Z

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

dyankowsky 2017-12-14T06:14:30.000054Z

transients!

borkdude 2017-12-14T07:30:28.000099Z

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

borkdude 2017-12-14T07:37:20.000067Z

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

borkdude 2017-12-14T07:41:39.000180Z

oh, wait… https://i.imgur.com/Wyl57tE.jpg

borkdude 2017-12-14T12:36:53.000020Z

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

borkdude 2017-12-14T12:37:00.000274Z

but I still have to fix the code 😛

borkdude 2017-12-14T14:15:53.000651Z

My day 14 is up: https://github.com/borkdude/aoc2017/blob/master/src/day14.clj

bhauman 2017-12-14T15:31:49.000360Z

my day 14

bhauman 2017-12-14T15:32:55.000383Z

thank goodness for all the perf work done on day 10

borkdude 2017-12-14T15:40:19.000081Z

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

borkdude 2017-12-14T15:40:53.000053Z

my part 1 is much slower though

borkdude 2017-12-14T15:41:53.000044Z

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

bhauman 2017-12-14T15:41:55.000433Z

yeah get-in is killing me

borkdude 2017-12-14T15:42:06.000132Z

oh day 10 optimizations, sorry I thought day 12

borkdude 2017-12-14T15:42:13.000004Z

yeah, I didn’t optimize day 10

bhauman 2017-12-14T15:42:53.000261Z

also my neighbors function could be improved for speed

bhauman 2017-12-14T15:43:49.000222Z

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

borkdude 2017-12-14T15:44:13.000850Z

probably

bhauman 2017-12-14T15:44:15.000041Z

for part 2

bhauman 2017-12-14T15:44:35.000774Z

cl-format is killing you on part 1

bhauman 2017-12-14T15:44:49.000028Z

its a dog yo

borkdude 2017-12-14T15:44:50.000584Z

the type annotations didn’t matter very much though

borkdude 2017-12-14T15:46:41.000598Z

@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

bhauman 2017-12-14T15:46:50.000249Z

also remember your hardware is showing up consistently faster than mine

bhauman 2017-12-14T15:47:03.000836Z

16 numbers

borkdude 2017-12-14T15:47:05.000299Z

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

bhauman 2017-12-14T15:47:17.000396Z

well its faster than mine 🙂

bhauman 2017-12-14T15:47:37.000487Z

mid 2014

borkdude 2017-12-14T15:48:05.000780Z

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

bhauman 2017-12-14T15:48:34.000494Z

🙂

bhauman 2017-12-14T15:48:55.000101Z

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

borkdude 2017-12-14T15:49:04.000070Z

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

borkdude 2017-12-14T15:49:18.000574Z

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

borkdude 2017-12-14T15:49:49.000337Z

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

bhauman 2017-12-14T15:50:25.000089Z

I'm iterating over the numbers not the hex characters

bhauman 2017-12-14T15:51:04.000560Z

1 number = 2 hex chars

borkdude 2017-12-14T15:51:52.000457Z

ah I see yeah

bhauman 2017-12-14T15:52:13.000355Z

that probably speeds it up as well

borkdude 2017-12-14T16:03:21.000332Z

with

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

borkdude 2017-12-14T16:04:01.000802Z

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

borkdude 2017-12-14T16:05:13.000065Z

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

borkdude 2017-12-14T16:09:04.000434Z

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

borkdude 2017-12-14T16:14:12.000088Z

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.

borkdude 2017-12-14T16:15:29.000291Z

mfikes: great job. Also revisited two previous days 🙂

borkdude 2017-12-14T16:16:44.000185Z

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”

mfikes 2017-12-14T16:19:45.000213Z

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

😮 2
mfikes 2017-12-14T16:25:09.000066Z

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

2017-12-14T16:38:13.000028Z

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

borkdude 2017-12-14T16:38:50.000878Z

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

bhauman 2017-12-14T18:24:25.000051Z

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

bhauman 2017-12-14T18:24:34.000418Z

@mfikes ^

bhauman 2017-12-14T18:25:26.000522Z

and congrats on what looks like a very speedy implementation

mfikes 2017-12-14T18:30:48.000624Z

@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

mfikes 2017-12-14T18:31:22.000667Z

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]

bhauman 2017-12-14T18:33:29.000511Z

hmmmm

mfikes 2017-12-14T18:33:49.000730Z

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

bhauman 2017-12-14T18:35:14.000259Z

as did I good sir, as did I