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
2021-02-18T00:01:19.041300Z

Is that significantly faster than using a transient vector with assoc! ?

Phil Shapiro 2021-02-18T00:08:07.043800Z

No idea about using assoc! I did try a few things on the way to aset/aget but they were too slow. If you want to try it out, my code is here: https://github.com/pshapiro4broad/advent2020/blob/main/src/day23.clj

2021-02-18T15:22:54.046600Z

My solution for day 23 runs in abount 9s with int-arrays, 13s with transient vectors, 18s with vanilla vectors here. fwiw & hth: https://github.com/next-mad-hatter/adventofcode/blob/master/src/aoc_2020/day_23.clj (transients) & https://github.com/next-mad-hatter/adventofcode/blob/master/src/aoc_2020/day_23_inplace.clj (int-arrays)

2021-02-18T16:37:24.047300Z

fascinating. thanks for sharing!

pavlosmelissinos 2021-02-18T17:11:00.058Z

I really struggled with day 7. I tried to solve it without recursion. Modeling the data into a structure that made sense to me was kinda hard but was nothing compared to coming up with the ugly, imperative code that did the actual computation 😛(inspired by the topological sorting algorithm; I used 2, or maybe 3, atoms). It's not public yet but I'll probably put it on gihub as soon as I get a little bit further. 1. Any of you come up with a pretty non-recursive solution? 2. The recursive solution feels much more natural to me, so I've also been wondering: why is recursion so frowned upon and more or less considered "inferior" to an iterative approach? I understand that in some cases it's hard to understand but in this case I really don't see any reason to avoid it.

2021-02-18T17:27:44.058600Z

AFAIK, the only non-recursive approach to topo sorting is to use a stack and do DFS, right? I have no clue how that would work in idiomatic Clojure. This is one of the top hits on Google, and it’s using recursion: http://hueypetersen.com/posts/2013/06/25/graph-traversal-with-clojure/ The examples here are also using recursion: https://github.com/life0fun/clojure-idiom/blob/master/graph.clj

👍 1
pavlosmelissinos 2021-02-18T18:39:34.059300Z

Indeed, stack + dfs is how I did it and it's probably the most unidiomatic thing ever written 😂 thanks for the response and the links 🙂

2021-02-18T19:54:41.059500Z

If you have some priority queue implementation then topological sort can be written as rather simple "loop" (whether it is expressed recursively or not is another matter somewhat)

2021-02-18T20:00:31.061100Z

true, the pseudeocode on the Wikipedia article does just that

2021-02-18T20:11:05.061300Z

One should take advice from people who consider recursion inferior with massive grain of salt afaiac 😉 Fwiw, or mayby luckily, this (it being frowned upon) had never been my experience. Which isn't to say recursion is equally useful in every programming language -- not every language supports tco, and even less support unlimited recursion in general. But if one wants to avoid mutable state there's no way around it.

2021-02-18T20:36:51.069300Z

From what I've heard, this year's aoc was a bit easier than some previous entries. I think I spent most time on (and had most fun with) day 11, seeing how far I could speed it up. Second would probably be day 23, trying out and comparing different vector types. The part I enjoyed the least was probably the last part of day 20, was a bit too long for me. And day 15 I cheesed, didn't feel like doing it at all 🙂

Phil Shapiro 2021-02-18T21:19:06.072900Z

Was that day 15 or 13? Because day 13 was a really hard one for me. And I agree day 20 part 2 was a lot of work. Most of the other days weren’t that bad. Overall it seemed easier to me than 2019, which I got about 1/2 way through, or 2018, which I also didn’t finish.

2021-02-18T21:25:27.073100Z

I skipped implementing day 15. For day 13 I had to dust off and look up some long forgotten math, but coding it wasn't that bad.

2021-02-18T21:30:42.073300Z

2020 is the first aoc year I took time to solve all problems (but not in december :)), only did a couple from 2018 before that, so cannot myself comment on difficulty compared to previous ones, only hearsay

2021-02-18T21:43:01.073600Z

of course, the difficulty is somewhat subject to variation depending on which building blocks of the solutions one is willing to take from libraries -- 2020's days 18 and 19 would have definitely been more work without instaparse 🙂

Phil Shapiro 2021-02-18T21:57:39.076800Z

I don’t really know clojure, doing advent2020 was my first use of it so I didn’t know about instaparse, although I did look at it for day 18. I ended up doing something cheesy with regular expressions. I’m sure using a proper parser would’ve been cleaner.

2021-02-18T22:32:07.077Z

Ah, similar story here :) Took aoc as opportunity to practice clojure, whenever people mentioned libraries here, put them on my to-check-out list..

2021-02-18T22:52:24.077200Z

I guess some would only consider implementing a complete parser to be proper solution.. But that's the nice thing about aoc, only you get to set your goals and constraints :)