4 ms·
> Therefore we could use a two-dimensional byte[][] array. However, due to (most likely premature) optimization, I chose one-dimensional, unrolled array Does t
by saagarjha 8y ago
> Therefore we could use a two-dimensional byte[][] array. However, due to (most likely premature) optimization, I chose one-dimensional, unrolled array
Does the Java compiler optimize this to be equivalent?
As an aside, I really hate problems like this that seem like they have a nice solution but then you end up brute forcing them. A family friend had one recently that she tore her hair out over for at least a week before finally accepting that there was no “simple” solution after confirmation from no fewer than five other people that they thought the problem was hard.
- munificent 8y ago> Does the Java compiler optimize this to be equivalent? No, it can't. `byte[][]` is an array of arrays, and that fact is user-visible because you can access any of the individual arrays, pass it to other functions, etc.
- saagarjha 8y agoBut you can do this is C, which has flat arrays. To “access” an individual array just grab the base address+array sizeelement sizeindex.
- kej 8y ago>A family friend had one recently that she tore her hair out over for at least a week before finally accepting that there was no “simple” solution after confirmation from no fewer than five other people that they thought the problem was hard. Is this something you can share? I'm curious what it was.
- saagarjha 8y agoSure, it was the problem listed on this page: https://www.rain.org/~mkummel/stumpers/22sep00a.html https://www.rain.org/~mkummel/stumpers/22sep00a.html. Basically it requires at least a bit of guess and checking, which made her feel as if she was doing it wrong since it seems like there would be a “formula” to do these that you could find if you did some algebra or something. I ended up writing a C++ program (yay, std::next_permutation) to brute force solutions but it could not find a pattern, especially if you try to increase the number of circles and look for patterns there.