Surface puzzle discussion

Thanks a lot.
100% !

Hi,
2 tests in python3 with the simple(st?) recursive algorithm:

  • my first try was using numpy.ndarrays of bools, and it works fine
  • my 2nd in pure python (lists of lists of bools), and it fails on problem 8 (due to time limit)

at the expense of increasing the max recursion depth of course.
x.

This puzzle doesn’t force you to use recursion or memoization, I cheesed it with just an iterative BFS that recalculated the size of each lake for every query. This makes the problem far easier than it should be. One case my code would’ve and should’ve failed on is a huge lake (or even one that takes up the entire area) that’s queried for 1000 times. I can’t think of a way to force the use of recursion, but this forces the use of memoization (or just precomputation, but lazily calculating lake sizes at need is more efficient).