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
Joe 2021-05-20T20:25:53.007200Z

I'm trying to do https://adventofcode.com/2015/day/6 part 2 which involves a conceptually simple problem. Described one way, you have a 1kx1k array and given several 'boxes' of indices within that array you have to change the values at each of those indices in the array (+1, -1, +2 depending on the instruction). Part 1 was a simple binary on/off. I solved it using sets of coordinates and unions/intersections, but it was very slow (~30seconds). For part 2 I could go down the route of a double reduce with a map of coord->value, but I'm guessing that will also be very slow. The solutions I've seen in languages like Rust seems to handle just looping through the instructions and banging on an array no problem. Should I look at just using a 1kx1k array here, and would that be more performant (like in the sub-5 second range)? Or is there another way to think about this problem? https://github.com/RedPenguin101/aoc2015/blob/main/src/aoc2015/day6.clj

2021-05-21T08:34:40.008100Z

making current transient might help

2021-05-21T08:35:34.008300Z

but you would need to adapt union/difference/exclusive-union to work with a transient set

2021-05-21T08:38:41.008500Z

the mutable array approach will be faster i think, hard to beat that approach

Joe 2021-05-21T09:26:41.009100Z

Gotcha, thanks!

Joe 2021-05-20T20:38:46.007700Z

Yeah, the map solution worked but took ~40 second

spfeiffer 2021-05-20T20:57:19.007900Z

I remember using mutable primitive arrays there for performance reasons.