3 kyu

Fluid Volume of a Heightmap

158 of 258thquinn
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • atirage Avatar

    Could someone please explain why is the correct volume 1 in the below test (I got it as one of the random tests, Python translation):

    14, 0, 0, 12, 12

    -5, 14, 10, 9, 9

    -5, 2, 7, 7, 14

    1, 5, 11, 13, 10

    9, 0, 1, 1, 7

    Thanks in advance!

  • ansis m Avatar

    I think it would be nice to add to description that big maps have hundreds of different height values. It would prevent warriors from going the wrong path.

    • Awesome A.D. Avatar

      This is an issue very specific to your personal approach (see your comment below), not a general issue. You just need to rethink how you tackle the problem. Hint: The number of depth levels should be irrelevant.

      Suggestion marked resolved by Awesome A.D. 4 years ago
  • ansis m Avatar

    This comment has been hidden.

  • Blind4Basics Avatar
  • Awesome A.D. Avatar

    Hello there!

    Rust translation ready for review! (It's pretty much a 1:1 copy of the Python test suite)

  • avkupwork Avatar

    I did not understand this kata. If you look at the example in the instructions, the bottom right element is 0. Hence, when filled, should the last column not contribute 63 and not 64?

    Also, what does 4*8 mean? Does each column of 8's (i.e. 4 8's) contribute 8?

    Does each column of 4 6's contribute 6? If so, how much would a column of 2 6's (the top two elements being 6 and the bottom 2 elements being 0) contribute?

    If there is a column, which reads, from top to bottom: 8 6 4 2 Is this possible? If so, how much does it contribute?

    @thquinn

    • Awesome A.D. Avatar

      It's a height map. Think of the numbers as heights of square columns stacked next to each other. Water spreads across equally high columns and trickles down into onto lower columns. Water flows in cardinal directions only, not diagonally. Hence the bottom right corner is not a leak. 6*4: There are 4 colums of height 0 surrounded on all sides by columns of height 6; 6-0 = 6 -> 4*6 4*8: Ther eare 4 columns of height 0 surrounded on all sides by columns of height 8; 8-0 = 8 -> 4*8.

      You can think of it like this: if it rained evenly all over the heightmap, where would water fill and stay?

  • Awesome A.D. Avatar

    Terrific kata. Had a blast with it.

  • JohanWiltink Avatar

    Might be a duplicate. Something with rainfall, possibly 1D instead of 2D. If I can find the original, I'll post a link.

  • ChristianECooper Avatar

    Nice kata - I enjoyed that! Thanks.