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
baritonehands 2018-12-09T01:46:40.041300Z

I ended up using loop, but had to use trampoline due to stack overflows: https://github.com/baritonehands/advent-of-code-2018/blob/master/src/aoc/dec8.clj

theeternalpulse 2018-12-09T02:19:03.041600Z

02

2️⃣ 1
0️⃣ 1
mfikes 2018-12-09T02:33:39.042100Z

Just don't try 08; that will cause an issue.

taylor 2018-12-09T06:19:25.043700Z

performance matters now

baritonehands 2018-12-09T07:17:49.044500Z

Yeah, my solution took 5 min to run, so 100x would be 8h

taylor 2018-12-09T07:23:13.044900Z

100x is ~5h for me

taylor 2018-12-09T07:24:11.045800Z

must be missing some intuition, there are people that solved both parts in less than 10m :thinking_face:

taylor 2018-12-09T07:25:26.046100Z

probably just gonna go to sleep and let it run haha

2018-12-09T07:29:57.049100Z

Does the given test case “13 players; last marble is worth 7999 points: high score is 146373” run for you guys? That’s the only one that fails for me 😮

2018-12-09T07:29:58.049200Z

I often have the experience of writing a slow solution and while it is running I write a faster solution that finishes before the first one did. This time while the second solution was running, I wrote a third solution that finishes even faster. And it’s a good thing too, because I realized, 20 minutes into running the second solution, that I used the wrong number as an input

mfikes 2018-12-09T16:00:00.113500Z

This is what actually happened with one of the Voyager spacecraft, right? (They launched it and years later developed better data compression algorithms, which let the images be sent back in reasonable time even though there was a comms channel slowdown due to a defective antenna or such.)

2018-12-09T07:31:23.049600Z

@meikemertsch advent2018.day9> (time (part2c 13 7999)) “Elapsed time: 30.633133 msecs” 146373

2018-12-09T08:39:52.061Z

I think I know why. Funnily enough my solution still worked on the input data :shocked_face_with_exploding_head:

2018-12-09T08:46:42.062Z

Yeah. I was wrong in calculating the new positions. I didn’t consider an important edge case

taylor 2018-12-09T07:32:16.049900Z

I got the same answer in 1199ms

2018-12-09T07:32:31.050Z

fudge 🙈 now I have no clue why that one doesn’t work but all others do

2018-12-09T07:33:07.050600Z

1.6 secs for running all five cases :thinking_face:

taylor 2018-12-09T07:33:39.050700Z

are you using persistent vectors?

2018-12-09T07:35:53.050900Z

No - I wrote a double-linked circular list out of volatiles. I feel dirty

taylor 2018-12-09T07:36:10.051100Z

nice

Average-user 2018-12-09T07:37:59.051800Z

I'm using clojure.data.finger-tree but still takes 3.4m for part1

taylor 2018-12-09T07:39:18.052400Z

part 1 is now 83s for me using vanilla vectors

Average-user 2018-12-09T07:39:54.052700Z

i was mistaken:

(time (part-1))
"Elapsed time: 924.570809 msecs"
388024

Average-user 2018-12-09T07:40:33.053200Z

forgot to change reduce conj by finget-trees/ft-concat

2018-12-09T07:40:34.053300Z

for part1 I used a naive vector approach. That was too slow , so then I used an ArrayList. That was much much faster, but still slow. So then I hacked together the circular list real fast. I can’t think of any way to do this efficienttly with a persistent data structure.

Average-user 2018-12-09T07:41:15.053600Z

(time (part-2))
"Elapsed time: 82914.062071 msecs"
3180929875

Average-user 2018-12-09T07:41:28.054Z

minute and some for part-2

2018-12-09T07:47:57.054500Z

Do you have an easy way to print out the removed values for that case?

2018-12-09T07:48:46.054700Z

https://pastebin.com/CvYTZnD9 is mine if you get stuck and want to compare later

fellshard 2018-12-09T07:58:25.056800Z

Hmm, I was wondering if a tree would be a better structure for arbitrary insertion / deletion. I'd heard good things about finger trees, it seems I should pay more attention to them.

fellshard 2018-12-09T08:00:43.058600Z

My attempt to use a straight Java Linked List did not fare well. In the end, I hopped over to straight Java and got pretty much instantaneous results. So I need to figure out where on earth I'm going wrong to get such poor performance. I think I cut out a great deal of potential reflection slowdown, so not sure what's up.

helios 2018-12-09T08:04:15.058900Z

my solution to part 1 is so slow 😢

helios 2018-12-09T08:04:29.059200Z

@taylor in the same boat as you i see 😄

baritonehands 2018-12-09T08:05:38.059600Z

Transients and subvec reduced my part1 by 10x

helios 2018-12-09T08:37:24.060500Z

@baritonehands yeah, good advice. I got to a speedup but my code still takes ~1 minute to run (70k marbles, 400 players)

helios 2018-12-09T08:37:38.060900Z

@baritonehands what kind of execution time you had for part 1 ?

2018-12-09T08:40:23.061400Z

718902 msecs for part one 😂 I have plenty of ideas how to make it better though

2018-12-09T08:41:52.061600Z

OMG the start of the next part is “Amused by the speed of your answer” 😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:😂 :rolling_on_the_floor_laughing:

😭 1
gklijs 2018-12-09T09:59:49.064300Z

Even for java there was no collection in the standard I could found for solving the second one.

uneman 2018-12-09T10:33:29.064400Z

I used ArrayDeque both O(1) for head and tail manipulation.

☝️ 1
uneman 2018-12-09T10:33:47.064700Z

java.util.ArrayDeque 🙂

ihabunek 2018-12-09T11:15:18.065700Z

i knew using lists for part 1 was silly but did not expect "Elapsed time: 527892.857699 msecs"

plexus 2018-12-09T12:07:13.066700Z

I ended up writing my own circular linked list implementation (after trying with regular lists and being waaaay too slow)

plexus 2018-12-09T12:08:25.067300Z

with that and after fixing some reflection call sites it's a comfortable 120ms for part 1 and 16sec for part 2

plexus 2018-12-09T12:09:46.068100Z

can't really do a doubly linked or circularly linked list that is functional though AFAIK so it's not a persistent data structure

borkdude 2018-12-09T12:14:12.069700Z

I get a boxed math warning on (- current-idx 7) where current-idx is a loop variable starting with 0. but when I place a type hint it says: can’t type hint primitive local. what does it want…

plexus 2018-12-09T12:25:01.070400Z

borkdude try [current-idx (long ...)] instead of [^long current-idx ...]

plexus 2018-12-09T12:26:40.070900Z

strange... from https://clojure.org/reference/java_interop#typehints

plexus 2018-12-09T12:26:52.071100Z

> (let [foo (int bar)] …​) is the correct way to get a primitive local. Do not use ^Integer etc.

plexus 2018-12-09T12:27:33.071600Z

Maybe put a (let [current-idx (long current-idx)] inside the loop?

borkdude 2018-12-09T12:28:13.071900Z

that works. strange that I need this?

plexus 2018-12-09T12:28:50.072600Z

It kind of makes sense if you think of it, if you put it in the loop [] it knows it will be a long in the first iteration, but you can recur something else later

borkdude 2018-12-09T12:30:01.073100Z

you can, but like with function arguments, the type hint is an invariant?

plexus 2018-12-09T12:30:39.073500Z

I guess you'll have to ask Rich... or dive into the compiler source 🙂

plexus 2018-12-09T12:31:40.074600Z

does that ^long (mod marble 23) make a difference? I thought type hints only worked on symbols...

plexus 2018-12-09T12:32:30.075300Z

this type hinting stuff remains a black art to me... adding tags left and right until the warnings go away 🙂

borkdude 2018-12-09T12:32:32.075500Z

yes

borkdude 2018-12-09T12:32:49.075800Z

same here. I usually only need this in advent of code..

plexus 2018-12-09T12:33:20.076300Z

I recently learned tags can also be strings, so you can do stuff like this ^"[Ljava.lang.String;"

plexus 2018-12-09T12:33:28.076600Z

i.e. "array of string"

borkdude 2018-12-09T12:38:57.077200Z

now it starts to make sense:

(defn foo []
  (loop [current-idx (long 0)]
    (- current-idx 7)
    #_(recur nil)))
you don’t get the boxed math warning if you remove the recur, so it has to do with that

2018-12-09T12:54:13.077600Z

ok, down to 45 secs for part one and out of ideas :thinking_face:

2018-12-09T13:12:19.079200Z

I trying to switch to java.util.LinkedList but I'm not able to call the remove(int index) method. It keeps calling the remove(Object o) method. Any ideas?

borkdude 2018-12-09T13:16:51.080200Z

My hunch is when it says: now do it x100 and it already takes long, that there might be some mathematical regularity you can take advantage of

genmeblog 2018-12-09T13:18:32.082100Z

just found out that using mapv instead of map on long lists give 6x speed gain 😕 (still optimizing day 6 and made 550ms instead of 3500ms)

athos 2018-12-09T13:20:15.082900Z

I implemented a doubly circularly linked list, perhaps almost same as @plexus's and it takes ~5sec for part 2 https://github.com/athos/advent-of-code-2018/blob/master/src/advent_of_code_2018/day09.clj

benoit 2018-12-09T13:27:32.083300Z

My solution for Day 9: https://github.com/benfle/advent-of-code-2018/blob/master/day9.clj

benoit 2018-12-09T13:29:50.085300Z

Using zippers. Ended up at 17s for part 2.

👍 4
borkdude 2018-12-09T13:34:21.085800Z

interesting to see that zippers have similar performance to the custom data structure of plexus

athos 2018-12-09T13:48:28.086900Z

My code got 1.7x faster by making it a little bit more branch prediction friendly 🙂

rmprescott 2018-12-09T14:32:13.089200Z

I really like @mfikes day 8 solution -- using the argument list as a stack in a shift reduce parser. A new trick to add to the bag-o-tricks.

2018-12-09T14:33:55.089600Z

strange, when running in the repl with time my part 2 now takes about 9 sec, running script/test-one it's about 23 sec.

taylor 2018-12-09T14:38:19.091200Z

Yeah I never would’ve thought to try zippers even though I try them in more unusual situations. Very cool

borkdude 2018-12-09T14:39:01.091700Z

@drowsy maybe because your REPL has a warmed up JVM? wild guess. what if you run the code multiple times in the test wrapped in a time?

taylor 2018-12-09T14:45:38.092900Z

A little bummed the last few days problems don’t lend themselves to visualization

taylor 2018-12-09T14:46:27.093600Z

Guess I could visualize a much smaller game of elf marbles

borkdude 2018-12-09T14:47:45.094400Z

I have the outcome for part 1 but didn’t look at the data. Why doesn’t it lend itself to visualization?

2018-12-09T14:48:54.094600Z

adding 4 (time (solve-2)) to the test brings the second run down a bit (about 20sec), but than it improves no further.

borkdude 2018-12-09T14:49:28.094800Z

what are you using to run the REPL, tools.deps or lein?

2018-12-09T14:49:36.095Z

tools.deps

borkdude 2018-12-09T14:50:08.095400Z

what if you use clojure.test/deftest with your own time call around the code?

2018-12-09T14:50:09.095600Z

but actually cursive, so I'm not sure how the repl is started exaclty

taylor 2018-12-09T14:50:37.096500Z

I was just thinking there are so many players and marbles it’d just be tiny pixels to look at

2018-12-09T14:51:02.096600Z

(time (part-2)) is fast in the REPL as well

borkdude 2018-12-09T14:52:13.096800Z

I mean use clojure.test/deftest instead of aoc.utils/deftest to exclude the possibility that it is my test macro

borkdude 2018-12-09T14:52:43.097Z

did you turn on unchecked math or anything?

2018-12-09T14:52:59.097300Z

yeah I did

borkdude 2018-12-09T14:53:12.097800Z

maybe you didn’t turn it on in the tests

2018-12-09T14:53:42.098500Z

well, it's in top of the file

ihabunek 2018-12-09T14:53:42.098700Z

i'm playing with java.util.LinkedList which has remove(int) and remove(object) overloaded methods it's always invoking the second, but i want the first, what can i do?

ihabunek 2018-12-09T14:53:57.099100Z

trying (.remove lst 1) to remove element at index 1

ihabunek 2018-12-09T14:54:05.099400Z

but end up removing element with value 1 from the list, if it exists

borkdude 2018-12-09T14:54:11.099500Z

can you try with binding around the test body?

ihabunek 2018-12-09T14:55:16.100Z

docs are here https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html

2018-12-09T14:55:55.100600Z

I asked this in #clojure and it seems you have to typehint the list itself in the call.

ihabunek 2018-12-09T14:56:29.101Z

cool, that works

ihabunek 2018-12-09T14:56:36.101300Z

weird solution though 🙂

ihabunek 2018-12-09T14:57:39.101600Z

and i need to typehint the index

taylor 2018-12-09T14:58:27.102500Z

I saw a really fast Clojure solution using linked list

2018-12-09T14:59:11.102700Z

So it's not your macro and binding doesn't help. I will have a look at the flight-recorder

ihabunek 2018-12-09T14:59:36.103300Z

i wanted to make my own list but don't have much time now so doing this

2018-12-09T15:04:56.103500Z

oh wait.... it's not even the same jvm. The REPL is running on a oracle jdk 8 on windows while the test script is an open jdk 10 on the linux subsystem.

plexus 2018-12-09T15:31:11.104400Z

To be fair my solution is completely unoptimized outside of the custom data structure.

mattly 2018-12-09T15:32:31.106Z

Wow, I feel happy that I reached for a vector zipper first. I figured it’d be slower than another solution but more convenient. Little did I know...

ihabunek 2018-12-09T15:37:11.106400Z

zippers! i forgot about those.

ihabunek 2018-12-09T15:37:30.106700Z

damn, now i have ideas for v4 and v5 of todays task 😄

2018-12-09T15:42:40.108200Z

I ended up just using two lists and no fancy mutable stuff. https://github.com/IamDrowsy/advent-of-cljc/blob/master/src/aoc/y2018/d09/iamdrowsy.cljc

ihabunek 2018-12-09T15:43:27.108600Z

😮

ihabunek 2018-12-09T15:43:39.109Z

that's just like my deque idea, but with lists

ihabunek 2018-12-09T15:43:43.109300Z

how long does it run for?

2018-12-09T15:44:46.110500Z

this is somewhat strange 🙂 no an openjdk 10 it's around 18 secs, in my repl running a oracle jvm 8 it's about 8 secs. So maybe it's a bit stressfull for the GC?

2018-12-09T15:46:39.111800Z

oh wow. On @borkdude circleCI the clojurescript version evens kills the vm because it's out of heap... maybe I need to do some tweaks

ihabunek 2018-12-09T15:55:45.112600Z

sorted-map works quickly?

mfikes 2018-12-09T15:57:09.113200Z

For part 1, it takes 566 ms, for part 2 maybe a minute or so

mfikes 2018-12-09T15:57:29.113400Z

Part 2 is 90 seconds

taylor 2018-12-09T16:01:21.114Z

Wow we got the exact same puzzle inputs

uneman 2018-12-09T16:08:24.114500Z

Fingertree(immutable) impl performs pretty good compared to java.util.ArrayDeque. Impressive! https://gist.github.com/namenu/402b46c61e385c801cdb4c150c3e4cd6

benoit 2018-12-09T16:18:29.115Z

I got to 7s for part two with custom data structure: https://github.com/benfle/advent-of-code-2018/blob/master/day9_alt.clj

baritonehands 2018-12-09T16:18:40.115300Z

Originally 300+ seconds, 30+ after

pesterhazy 2018-12-09T16:50:55.116900Z

I'm finding Day 9 very hard - not to get the right result but to get Part 2 to complete in time. My algorithm's time complexity is not good enough

pesterhazy 2018-12-09T16:52:11.117200Z

what am I missing ?!

mfikes 2018-12-09T16:53:51.118200Z

Oops, I had written mine in ClojureScript, and while it was working in Clojure, it was using rationals. Switching to doubles dropped part two to 30 seconds.

pesterhazy 2018-12-09T16:54:16.118700Z

I have two impls, one based on PersistentVector and one based on sorted-map: https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle09.clj#L7

pesterhazy 2018-12-09T16:54:57.119500Z

sorted-map is slightly faster but still takes 100+ s for Part 1 - I can't even dream of trying Part 2

mfikes 2018-12-09T16:55:26.120200Z

@pesterhazy Mine is sorted map as well; taking a look at yours

pesterhazy 2018-12-09T16:55:30.120400Z

do you have a gentle hint for me @mfikes?

mfikes 2018-12-09T16:57:40.121600Z

@pesterhazy I have to run out for a while, but quickly scanning through your solution, I don't see use of subseq. I was using that to find nearby indices (and rsubseq to find one 7 back)

gklijs 2018-12-09T16:58:50.122Z

lol, my second one now runs faster then the first one

pesterhazy 2018-12-09T16:59:42.122600Z

@mfikes d'oh!

borkdude 2018-12-09T16:59:48.122800Z

my naive pure clojure vector based solutions runs in 85 seconds for part 1. I tried https://github.com/clojure/core.rrb-vector but got an index out of bounds exception with it

mfikes 2018-12-09T17:01:51.125100Z

The main idea of the sorted-map approach is: Use it as a poor man's mutable linked list. To insert and remove you assoc and dissoc, and to navigate forward and back, subseq and rsubseq. And Paulus and I have the same indexing strategy: Use doubles as your index and use midpoint to insert a marble between.

mfikes 2018-12-09T17:17:15.127200Z

This was the first problem where I had to resort to transducers to bypass ClojureScript's head holding / lack of locals clearing.

mfikes 2018-12-09T17:17:40.127500Z

(There were several of those last year.)

mfikes 2018-12-09T17:18:43.128100Z

If you're curious, it is specifically this use of nth' here https://github.com/mfikes/advent-of-code/blob/master/src/advent_2018/day_09.cljc#L41 Otherwise regular nth holds head on the iterated sequence.

pesterhazy 2018-12-09T18:27:51.128800Z

Ok here's my complete Day 09: https://github.com/pesterhazy/advent2018/blob/master/src/advent/puzzle09.clj#L38

pesterhazy 2018-12-09T18:28:20.129400Z

solution-2 takes 37s

pesterhazy 2018-12-09T18:29:21.130Z

a far from the estimated 12h+ of my first PersistentVector approach

pesterhazy 2018-12-09T18:30:38.131100Z

@mfikes thanks so much for getting me unstuck by mentioning subseq and especially rsubseq — these are functions I genuinely didn't know about (well I heard them mentioned here a few days ago but promptly forgot)

pesterhazy 2018-12-09T18:31:54.132300Z

using doubles as indices works well but honestly we were lucky that we didn't reach the point where floating-point precision prevents squeezing in new positions

fellshard 2018-12-09T18:32:10.132400Z

This fixed itself when I type-hinted the list as a ^java.util.LinkedList and the remove method argument as an int.

pesterhazy 2018-12-09T18:43:28.133500Z

I'm very curious about what datastructures other JVm based solutions use

baritonehands 2018-12-09T18:45:40.134200Z

Got 58ms and 6864ms with my own transient map based linked list:

defn ll-init [n]
  (let [node (transient {:value n})]
    (assoc! node :next node)
    (assoc! node :prev node)
    node))

(defn ll-insert [{:keys [next] :as root} n]
  (let [node (transient {:value n})]
    (assoc! node :next next :prev root)
    (assoc! next :prev node)
    (assoc! root :next node)
    node))

(defn ll-remove [{:keys [next prev value] :as node}]
  (assoc! next :prev prev)
  (assoc! prev :next next)
  [next (:value node)])

(defn ll-nth [node idx]
  (nth (iterate (if (neg? idx) :prev :next) node) (Math/abs (int idx))))

pesterhazy 2018-12-09T18:47:46.134900Z

Hm, aren't you supposed to close transients by calling persistent!?

pesterhazy 2018-12-09T18:51:27.135Z

Thanks for mentioning Deque, wasn't aware of that. Did you end up using a Deque? Isn't it necessary to insert marbles at arbitrary positions, not just at head or tail?

pesterhazy 2018-12-09T18:54:02.136300Z

very cool

baritonehands 2018-12-09T18:54:03.136600Z

Is that always necessary? They won’t just get cleaned up when I forget the reference?

borkdude 2018-12-09T18:54:21.136900Z

Only if you want a persistent I guess

pesterhazy 2018-12-09T18:55:31.137300Z

The docs say, > Note in particular that transients are not designed to be bashed in-place. You must capture and use the return value in the next call.

baritonehands 2018-12-09T18:56:10.137700Z

I store the return value in a seq

pesterhazy 2018-12-09T18:58:49.138800Z

I can't believe how simple day9 can be with a good Deque implementation: https://www.reddit.com/r/adventofcode/comments/a4i97s/2018_day_9_solutions/ebepyc7/

☝️ 2
baritonehands 2018-12-09T19:22:30.141600Z

Transients still worked for me, maybe because they were all of size 3? I would assume they change reference when the implementation changes at a certain size boundary

pesterhazy 2018-12-09T19:27:50.142700Z

Reading up on deque, you can write rotate easily by popping on one side and pushing on the other - that should work with Java's ArrayDeque as well

pesterhazy 2018-12-09T19:29:23.143100Z

I wonder if a PersistentDeque would be feasible?

misha 2018-12-09T19:32:02.143700Z

I promise I won't read spoilers

Average-user 2018-12-09T19:33:05.144500Z

@pesterhazy I do something like that. The rotate is implemented with ft-split-at from clojure.data.finger-trees

pesterhazy 2018-12-09T19:34:42.145200Z

pjstadig has a persistent Deque implementation: https://github.com/pjstadig/deque-clojure/blob/master/src/name/stadig/deque/protocol.clj#L16

☝️ 1
pesterhazy 2018-12-09T19:35:57.146Z

@lucaspolymeris nice - how long does it take to answer part 2?

benoit 2018-12-09T19:36:20.146500Z

@pesterhazy Thanks for the link to dequeue. I forgot about this one. That seems like the right data structure for the problem, yes.

Average-user 2018-12-09T19:36:41.146600Z

Not very fast 1m aprox

Average-user 2018-12-09T19:37:22.147400Z

What would be the gain against finger-tree?

pesterhazy 2018-12-09T19:37:26.147500Z

that's still pretty good for a pure solution!

pesterhazy 2018-12-09T19:37:38.147700Z

my sorted-set approach takes ~30s

Average-user 2018-12-09T19:38:22.148200Z

Do have the link? Is it pure?

benoit 2018-12-09T19:39:32.149300Z

No idea. I never took the time to look at finger trees. Maybe I should. But for this problem deque's complexity properties seem appropriate.

benoit 2018-12-09T19:41:17.150800Z

And more importantly it makes the solution pretty clear. I tried to something similar w/ my solution but zippers require a rewinding that is not very elegant. And then my custom data structure is pretty specific to the problem so not great either 🙂

Average-user 2018-12-09T19:42:18.151900Z

R u going to implement the dequeue one? I'm interested to compare times with finger trees

Average-user 2018-12-09T19:42:34.152400Z

So if u do, could you please share it?

benoit 2018-12-09T20:02:40.154400Z

Using the java.util.LinkedList which implements java.util.Deque I'm getting between 2 and 3 seconds.

mfikes 2018-12-09T20:03:21.154600Z

Mine is essentially the same and is also ~30s

Average-user 2018-12-09T20:06:45.156Z

But those r not pure i suppose

gklijs 2018-12-09T20:07:04.156600Z

I got 33ms, after a lot of iterations, with Java

👍 1
🤯 1
benoit 2018-12-09T20:16:13.157Z

@gklijs For part 2?

gklijs 2018-12-09T20:20:22.157900Z

Yes, the first one runs almost 100 times faster.

misha 2018-12-09T20:31:28.158600Z

33ms part 2? you guys are killing me :harold:

Average-user 2018-12-09T20:44:29.159200Z

Which has been your favourite day so far?

2018-12-09T20:45:04.159300Z

Day 7! It left me singing and dancing

benoit 2018-12-09T20:55:50.159800Z

@gklijs The "history" trick is neat.

benoit 2018-12-09T20:58:32.160700Z

With Java data structures (Deque and long array to keep scores). I'm done with this problem 🙂 https://github.com/benfle/advent-of-code-2018/blob/master/day9_alt2.clj

2018-12-09T21:47:07.161100Z

m

2018-12-09T21:52:43.161200Z

Today’s. I built a data structure just for it I was proud of 😄

1
2
pesterhazy 2018-12-09T21:56:04.161900Z

My conclusions after (a very long) day 09: https://github.com/pesterhazy/advent2018/blob/master/journal.md#day-09

1
pesterhazy 2018-12-09T21:57:16.162800Z

@gklijs is your solution available online?

2018-12-09T21:57:31.163100Z

lots of solutions here

2018-12-09T21:57:43.163400Z

I made a mutable doubly-linked circular list

2018-12-09T22:01:31.163700Z

looks pretty much like the python solution

2018-12-09T22:01:40.164Z

that @pesterhazy posted

pesterhazy 2018-12-09T22:03:33.164200Z

Nice solution in Java: https://www.reddit.com/r/adventofcode/comments/a4i97s/2018_day_9_solutions/ebetdc5/

2018-12-09T22:04:07.164600Z

If I only knew the word “deque”

2018-12-09T22:04:24.164900Z

oh well, had fun making my own 🙂

2018-12-09T22:12:11.165300Z

I’m at 20ms for p1, 9s for p2

2018-12-09T22:12:27.165700Z

lots of obvious waste to trim

benoit 2018-12-09T22:17:32.167600Z

@potetm same here: zip -> own deque -> java deque 🙂

2018-12-09T22:17:47.167900Z

pure clojure using deftype w/ mutable fields

2018-12-09T22:17:59.168300Z

yeah I bet java deque is sig better 🙂

2018-12-09T22:18:10.168800Z

you see a sig timing dif @me1740?

benoit 2018-12-09T22:18:48.169400Z

16 s -> 7 s -> 1s roughly

2018-12-09T22:19:00.169700Z

😕 yeah I guess java deque is next for me

benoit 2018-12-09T22:20:36.171100Z

Interestingly the timing w/ Java data structure seem to vary much more than the Clojure data structures. I'm not familiar enough w/ the internals of either to explain why.

2018-12-09T22:21:24.171800Z

mine varies quite a bit actually

2018-12-09T22:21:26.172Z

no idea why

2018-12-09T22:21:33.172300Z

as short as 2s, as long as 10

2018-12-09T22:21:38.172500Z

GC I presume

2018-12-09T22:21:57.172800Z

very odd

benoit 2018-12-09T22:22:05.173Z

Yeah the difference seems big

2018-12-09T22:23:05.173300Z

"Elapsed time: 8461.775695 msecs"
=> [344 3038972494]
"Elapsed time: 11364.651846 msecs"
=> [344 3038972494]
"Elapsed time: 2761.024937 msecs"
=> [344 3038972494]
"Elapsed time: 9324.289621 msecs"
=> [344 3038972494]
"Elapsed time: 3111.038354 msecs"
=> [344 3038972494]

2018-12-09T22:23:13.173600Z

:man-shrugging:

pesterhazy 2018-12-09T22:23:23.173900Z

This one takes 2.3s for p2: https://www.reddit.com/r/adventofcode/comments/a4i97s/2018_day_9_solutions/ebetdc5/

2018-12-09T22:23:44.174100Z

yeah but they cheated

2018-12-09T22:23:47.174300Z

perf enhancing drugs

2018-12-09T22:23:55.174500Z

:troll:

2018-12-09T22:24:23.174900Z

New talk idea: “Mutation is a performance enhancing drug.”

ihabunek 2018-12-09T22:37:53.175200Z

lol, i did that same thing in clojure https://git.sr.ht/%7Eihabunek/aoc2018/tree/master/clojure/src/aoc2018/day09.clj

ihabunek 2018-12-09T22:38:28.175800Z

my excuse: i was going for a functional solution but it was too slow and i wanted to have a solution today 😄

mfikes 2018-12-09T22:52:12.177100Z

Has anyone built a rotate-based solution based on core.rrb-vector?

taylor 2018-12-09T22:52:45.178400Z

My slightly optimized persistent vector solution was going to run for about 4 or 5 hours. Then I switched to finger tree at recommendation in this channel

mfikes 2018-12-09T22:54:09.179600Z

I figure you can easily build a rotate operation on top of core.rrb-vector, getting two subvec from the right place, and then doing a catvec on them. Maybe that would be O (log n) ...

mfikes 2018-12-09T23:52:44.181700Z

Damn, core.rrb-vector is broken. You get ClassCastExceptions deep down in its implementation. This code works if you comment the core.rbb-vector and uncomment the regular Clojure persistent vector calls. https://github.com/mfikes/advent-of-code/blob/day-9-rotate/src/advent_2018/day_09.cljc

😱 1
mfikes 2018-12-09T23:56:27.183400Z

That's unfortunate... the core.rrb-vector implementation works for (play 9 25), but not for larger problems, where it starts to crap out.

mfikes 2018-12-09T23:58:54.185Z

So, the fastest pure solution, using non-custom data structures is still sorted-map? Dang! I was hoping this core.rrb-vector approach would be fast, pure, and fairly idiomatic (and non-custom).