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-15T03:28:20.000045Z

I started trying to read this as a solution to day14 and my brain started to hurt lol.. need more morning coffee

2017-12-15T04:46:26.000186Z

another nice use of tree-seq, @bhauman!

2017-12-15T04:46:38.000127Z

i went the loop/recur route again for my flood

grzm 2017-12-15T05:04:18.000195Z

Is it wrong that I as someone who likes coding have an aversion to binary numbers? Two days in a row 😞

2017-12-15T05:09:06.000086Z

uh oh

2017-12-15T05:09:12.000128Z

40,000,000.. lol

2017-12-15T05:20:18.000102Z

hmm .. xor for speedup maybe?

2017-12-15T05:36:05.000143Z

ok, not too slow.. I'm sure there's room for improvement though!

grzm 2017-12-15T05:44:29.000020Z

Wow. I love clojure.

3
fellshard 2017-12-15T06:08:28.000170Z

The binary isn't too bad here, thankfully.

borkdude 2017-12-15T08:34:48.000252Z

today was easy, luckily

ihabunek 2017-12-15T09:02:02.000016Z

i'm learning that lazy sequences are slow

ihabunek 2017-12-15T09:02:15.000254Z

and recursion is preferred for this kind of problem

ihabunek 2017-12-15T09:02:27.000331Z

but not as nice to look at

borkdude 2017-12-15T09:05:38.000077Z

@ihabunek what kind of performance are you looking at?

borkdude 2017-12-15T09:05:42.000183Z

with lazy seqs

erwin 2017-12-15T09:07:38.000213Z

for me lazy-seq + count is 20 seconds range

borkdude 2017-12-15T09:07:54.000130Z

I got 11 for part 1, 7 for part 2

borkdude 2017-12-15T09:08:00.000205Z

I’m using loop recur + iterate

erwin 2017-12-15T09:08:38.000358Z

for reference: pypy loop with generators is instantaneous

borkdude 2017-12-15T09:09:05.000284Z

like below 10ms?

erwin 2017-12-15T09:12:27.000200Z

no, 0.7 seconds for part-2, with pypy day15.py so including startup time

ihabunek 2017-12-15T09:15:19.000366Z

I'm getting around 30s for both parts. Using lazy-seq for generators

2017-12-15T09:15:55.000229Z

I'm getting 7s for first and 5s for 2nd using lazy; ~1s using recursion for first part

ihabunek 2017-12-15T09:16:41.000157Z

Huh. Can I see your code?

ihabunek 2017-12-15T09:16:55.000072Z

Mine ^

ihabunek 2017-12-15T09:18:32.000109Z

Have not used iterate before. Will look into it

2017-12-15T09:18:54.000408Z

good one to use for these kinds of "feedback" problems

2017-12-15T09:20:24.000379Z

oh, i like your lower-bits fn, stealing that 😛

erwin 2017-12-15T09:29:25.000282Z

@minikomi your implementation is not correct

2017-12-15T09:29:38.000270Z

oh?

erwin 2017-12-15T09:29:54.000495Z

try it on A: 512 and B: 191

erwin 2017-12-15T09:29:58.000204Z

for part2

erwin 2017-12-15T09:30:24.000309Z

should be 323, yours gives 301

2017-12-15T09:32:13.000112Z

weird

2017-12-15T09:32:15.000455Z

what's gone wrong?

2017-12-15T09:32:55.000328Z

for part 1 - 567?

erwin 2017-12-15T09:33:07.000262Z

https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day15.clj#L28 that drop should be on lines 39 and 40

erwin 2017-12-15T09:35:49.000105Z

I had the same problem in my code, took me some time to find the problem 😞 (and some attempts typing the wrong answer 8))

2017-12-15T09:37:55.000307Z

Can you explain conceptually what the difference is?

erwin 2017-12-15T09:43:26.000182Z

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

2017-12-15T09:43:40.000033Z

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

erwin 2017-12-15T09:44:12.000156Z

no it compares the wrong values for the complete range

borkdude 2017-12-15T09:46:29.000276Z

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

2017-12-15T09:48:16.000048Z

ok, moved the drops inside the filters -- fixes the part2 for the seeds you gave

karlis 2017-12-15T09:48:25.000312Z

day 15 from me: https://github.com/skazhy/advent/blob/master/src/advent/2017/day15.clj currently ~ 18 seconds for 1st / 10 for 2nd.

2017-12-15T09:48:32.000369Z

just got lucky with my seeds i guess 😛

erwin 2017-12-15T09:50:30.000295Z

I learned that iterate doesn't give (f x) (f (f x)) but x (f x) 🤓

2017-12-15T09:53:36.000092Z

Ah, because 512 gets grouped with the first generated b value.. right

borkdude 2017-12-15T10:55:36.000279Z

So… it turns out to be this sequence: https://en.wikipedia.org/wiki/Lehmer_random_number_generator

ihabunek 2017-12-15T10:58:13.000274Z

nice find

orestis 2017-12-15T10:59:26.000116Z

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

ihabunek 2017-12-15T11:02:31.000094Z

@borkdude looking at your implementation of multiple-of, what's wrong with (zero? (mod x y)) ?

borkdude 2017-12-15T11:02:45.000154Z

@ihabunek nothing, but this is slightly faster 🙂

ihabunek 2017-12-15T11:02:54.000260Z

ok, i guessed as much 🙂

borkdude 2017-12-15T11:03:07.000259Z

Could be even faster when you inline 4 and 8

ihabunek 2017-12-15T11:03:12.000112Z

hm, quick-bench sounds interesting

ihabunek 2017-12-15T11:03:27.000045Z

would partial application be as fast as inlining?

borkdude 2017-12-15T11:03:39.000172Z

no, it would still do the calculation when you call the partial

orestis 2017-12-15T11:04:12.000274Z

My day14 part 2 (flood fill) is at 7 seconds, using mostly plain sets.

ihabunek 2017-12-15T11:05:25.000019Z

i "cheated" on day14... used a transient set, and it's well under 1s 🙂

ihabunek 2017-12-15T11:05:42.000212Z

i guess localized mutability is ok though

orestis 2017-12-15T11:06:05.000306Z

For today, 5s and 7s.

borkdude 2017-12-15T11:06:43.000495Z

@orestis cool. Wonder why my part 2 is faster than part 1, but it may be the input

orestis 2017-12-15T11:06:45.000181Z

Ah, iterate was what I should use.

orestis 2017-12-15T11:07:16.000284Z

I was googleing “clojure reduce infinite sequence” 🙂

ihabunek 2017-12-15T11:07:27.000131Z

iterate is my function of the day as well

borkdude 2017-12-15T11:08:32.000187Z

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

ihabunek 2017-12-15T11:08:57.000240Z

yes, i understand

ihabunek 2017-12-15T11:09:05.000316Z

makes sense

ihabunek 2017-12-15T11:09:33.000098Z

basically it only binds one of the inputs

borkdude 2017-12-15T11:10:44.000052Z

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

ihabunek 2017-12-15T11:11:42.000157Z

i think my code is slow because of the way i use sequences more than comparing bits.

ihabunek 2017-12-15T11:12:12.000008Z

does this slack have a bot which runs clojure code like the irc channel does?

ihabunek 2017-12-15T11:12:46.000361Z

cool 😄

borkdude 2017-12-15T11:14:27.000055Z

@ihabunek how does that work again?

ihabunek 2017-12-15T11:15:05.000212Z

/clj (println 1)

borkdude 2017-12-15T11:15:13.000131Z

thanks

ihabunek 2017-12-15T11:16:46.000409Z

takes a little while though

ihabunek 2017-12-15T11:17:42.000310Z

and now let's try /clj (range) 🙂

ihabunek 2017-12-15T11:18:10.000292Z

i'll be good and not do that 🙂

ihabunek 2017-12-15T11:19:22.000180Z

using unchecked-short instead of (bit-and a 0xffff) does nothing for my performance

ihabunek 2017-12-15T11:19:40.000203Z

actually, it's slightly worse 🙂

borkdude 2017-12-15T11:20:37.000034Z

@ihabunek it’s probably ok

borkdude 2017-12-15T11:20:45.000258Z

oh no…

ihabunek 2017-12-15T11:20:50.000292Z

hah

ihabunek 2017-12-15T11:21:11.000161Z

😄

borkdude 2017-12-15T11:21:33.000289Z

sorry… I can’t remove it…

ihabunek 2017-12-15T11:21:46.000252Z

now you know how to DOS this slack

borkdude 2017-12-15T11:22:01.000283Z

who is the admin of this channel? 😉 @pvinis can you remove the range…

ihabunek 2017-12-15T11:24:56.000061Z

@borkdude what do you get by prefixing things with ^long

ihabunek 2017-12-15T11:25:08.000302Z

just so it doesn't use int?

borkdude 2017-12-15T11:25:24.000174Z

@ihabunek evaluate the settings from the comment section at the bottom, then you’ll see warnings about boxing

borkdude 2017-12-15T11:25:27.000422Z

so it’s to prevent boxing

ihabunek 2017-12-15T11:25:36.000144Z

ah, ok

borkdude 2017-12-15T11:29:34.000290Z

Terribly sorry for the long output by range… didn’t know it would consume that much estate… pinging an admin who can remove it.

ihabunek 2017-12-15T11:31:26.000156Z

i disovered parinfer for sublime text and don't know how i ever managed to code clojure before that

ihabunek 2017-12-15T11:31:34.000377Z

i'm guessing half people here are on emacs

mikelis 2017-12-15T12:08:54.000036Z

I’m using Cursive in IntelliJ and it also has parinfer

mikelis 2017-12-15T12:09:03.000197Z

Although not the latest and greatest version 3

mikelis 2017-12-15T12:09:09.000144Z

btw here’s my solution for today https://github.com/axelarge/advent-of-code/blob/master/src/advent_of_code/2017/day15.clj

robert-stuttaford 2017-12-15T12:28:18.000375Z

all cleaned up 👼

borkdude 2017-12-15T12:28:24.000243Z

thanks rob 🙂

robert-stuttaford 2017-12-15T12:28:35.000112Z

y’all have fun now - merry conjmas!

borkdude 2017-12-15T12:28:48.000121Z

xmas… x for transducers you know 😉

robert-stuttaford 2017-12-15T12:29:20.000324Z

xform-mas? 😎

ihabunek 2017-12-15T13:07:49.000133Z

switching between advent of clojure in the morning and python for my actual job is messing with my brain

borkdude 2017-12-15T13:20:36.000063Z

it’s a nerd snipe

orestis 2017-12-15T14:20:08.000171Z

Nice solution @mikelis.vindavs

bhauman 2017-12-15T14:59:36.000433Z

just went for the straightforward approach today nothing special

borkdude 2017-12-15T15:02:16.000037Z

@bhauman still cool!

👍 2
mfikes 2017-12-15T17:42:10.000320Z

I messed around with macros to get it down to around 236 ms for part 1 and 675 ms for part 2.

👍 1
🤘 2
mfikes 2017-12-15T18:31:03.000239Z

Ahh cool. I forgot about unchecked-math and boxing. Fixing that results in 165 ms for part 1 and 295 ms for part 2.

borkdude 2017-12-15T18:45:11.000247Z

Very cool Mike!

borkdude 2017-12-15T18:46:31.000604Z

Good idea to use macros for inlining.

borkdude 2017-12-15T23:00:15.000059Z

@mfikes Am I right that the macro approach only helps for inlining var values, but otherwise doesn’t help very much?

mfikes 2017-12-16T10:38:51.000012Z

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.