Fork me on GitHub

I'm trying to do 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?


Yeah, the map solution worked but took ~40 second


I remember using mutable primitive arrays there for performance reasons.


making current transient might help


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


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


Gotcha, thanks!