I started trying to read this as a solution to day14 and my brain started to hurt lol.. need more morning coffee
another nice use of tree-seq
, @bhauman!
i went the loop/recur route again for my flood
Is it wrong that I as someone who likes coding have an aversion to binary numbers? Two days in a row 😞
uh oh
40,000,000.. lol
hmm .. xor for speedup maybe?
ok, not too slow.. I'm sure there's room for improvement though!
Wow. I love clojure.
The binary isn't too bad here, thankfully.
today was easy, luckily
i'm learning that lazy sequences are slow
and recursion is preferred for this kind of problem
but not as nice to look at
@ihabunek what kind of performance are you looking at?
with lazy seqs
for me lazy-seq + count is 20 seconds range
I got 11 for part 1, 7 for part 2
I’m using loop recur + iterate
for reference: pypy loop with generators is instantaneous
like below 10ms?
no, 0.7 seconds for part-2, with pypy day15.py
so including startup time
I'm getting around 30s for both parts. Using lazy-seq for generators
I'm getting 7s for first and 5s for 2nd using lazy; ~1s using recursion for first part
Huh. Can I see your code?
https://github.com/ihabunek/aoc2017/blob/master/src/aoc2017/day15.clj
Mine ^
https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day15.clj
Have not used iterate before. Will look into it
good one to use for these kinds of "feedback" problems
oh, i like your lower-bits fn, stealing that 😛
@minikomi your implementation is not correct
oh?
try it on A: 512 and B: 191
for part2
should be 323, yours gives 301
weird
what's gone wrong?
for part 1 - 567?
https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day15.clj#L28 that drop should be on lines 39 and 40
I had the same problem in my code, took me some time to find the problem 😞 (and some attempts typing the wrong answer 8))
Can you explain conceptually what the difference is?
first: part1 is also not correct but, there it doesn't matter, because there is no filtering involved, and the start values do not have the same 16 lower bits. Your (and my) code generates 277, (* 277 16807) and so on, but the start value should not be in the generated steps (check with example in problem). For part 2, the modulo 8 and 4 checks allows the start value for input 512 and the pairs are of by 1 for the complete range
oh, i see, i want to drop the first generated value - since they're seeds and not generated, but by having the drop where i had it, it drops the first filterted generated value
no it compares the wrong values for the complete range
Btw, here’s my code: https://github.com/borkdude/aoc2017/blob/master/src/day15.clj I think it could be optimized if I would loop/recurify the ranges as well
ok, moved the drops inside the filters -- fixes the part2 for the seeds you gave
day 15 from me: https://github.com/skazhy/advent/blob/master/src/advent/2017/day15.clj currently ~ 18 seconds for 1st / 10 for 2nd.
just got lucky with my seeds i guess 😛
I learned that iterate doesn't give (f x) (f (f x)) but x (f x) 🤓
Ah, because 512 gets grouped with the first generated b value.. right
So… it turns out to be this sequence: https://en.wikipedia.org/wiki/Lehmer_random_number_generator
nice find
Hi all! I had to skip yesterday because I was travelling, but I’m now all caught up. Day 14: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day14.clj Day 15: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day15.clj
@borkdude looking at your implementation of multiple-of
, what's wrong with (zero? (mod x y))
?
@ihabunek nothing, but this is slightly faster 🙂
ok, i guessed as much 🙂
Could be even faster when you inline 4 and 8
hm, quick-bench sounds interesting
would partial application be as fast as inlining?
no, it would still do the calculation when you call the partial
My day14 part 2 (flood fill) is at 7 seconds, using mostly plain sets.
i "cheated" on day14... used a transient set, and it's well under 1s 🙂
i guess localized mutability is ok though
For today, 5s and 7s.
@orestis cool. Wonder why my part 2 is faster than part 1, but it may be the input
Ah, iterate
was what I should use.
I was googleing “clojure reduce infinite sequence” 🙂
iterate
is my function of the day as well
@ihabunek Better example:
boot.user=> (defn inc* [x] (println "inc") (inc x))
#'boot.user/inc*
boot.user=> (defn f [x y] (let [x' (inc* x)] (+ x' y)))
#'boot.user/f
boot.user=> (f 1 1)
inc
3
boot.user=> (def g (partial f 1))
#'boot.user/g
boot.user=> (g 1)
inc
3
In other words: partial does nothing for inlining stuffyes, i understand
makes sense
basically it only binds one of the inputs
I wonder if there is a faster way of comparing the lowest 16 bits than (== (unchecked-short ..) (unchecked-short ..))
, maybe something using xor
, or maybe it already does that on a lower level
i think my code is slow because of the way i use sequences more than comparing bits.
does this slack have a bot which runs clojure code like the irc channel does?
cool 😄
@ihabunek how does that work again?
/clj (println 1)
thanks
takes a little while though
and now let's try /clj (range)
🙂
i'll be good and not do that 🙂
using unchecked-short
instead of (bit-and a 0xffff)
does nothing for my performance
actually, it's slightly worse 🙂
@ihabunek it’s probably ok
oh no…
hah
😄
sorry… I can’t remove it…
now you know how to DOS this slack
who is the admin of this channel? 😉 @pvinis can you remove the range…
@borkdude what do you get by prefixing things with ^long
just so it doesn't use int?
@ihabunek evaluate the settings from the comment section at the bottom, then you’ll see warnings about boxing
so it’s to prevent boxing
ah, ok
Terribly sorry for the long output by range… didn’t know it would consume that much estate… pinging an admin who can remove it.
i disovered parinfer for sublime text and don't know how i ever managed to code clojure before that
i'm guessing half people here are on emacs
I’m using Cursive in IntelliJ and it also has parinfer
Although not the latest and greatest version 3
btw here’s my solution for today https://github.com/axelarge/advent-of-code/blob/master/src/advent_of_code/2017/day15.clj
all cleaned up 👼
thanks rob 🙂
y’all have fun now - merry conjmas!
xmas… x for transducers you know 😉
xform-mas? 😎
switching between advent of clojure in the morning and python for my actual job is messing with my brain
it’s a nerd snipe
Nice solution @mikelis.vindavs
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day15.clj
just went for the straightforward approach today nothing special
@bhauman still cool!
https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_15.cljc
I messed around with macros to get it down to around 236 ms for part 1 and 675 ms for part 2.
Ahh cool. I forgot about unchecked-math and boxing. Fixing that results in 165 ms for part 1 and 295 ms for part 2.
Very cool Mike!
Good idea to use macros for inlining.
@mfikes Am I right that the macro approach only helps for inlining var values, but otherwise doesn’t help very much?
My initial motivation was to inline the arguments. I think you had also mentioned that inlining the 4 and 8 resulted in faster performance than if they were passed as arguments. I was seeing a similar effect. But var inlining is probably another effect. One odd thing I never figured out was that if I macroexpanded the solution to part 1, the cleaned up expansion inexplicably ran slower.