Your task is to check the volume of water in a pool. Your have to create a program that takes in a input that is represented by an 10 by 10
grid of integers, with heights ranging from A=1
to Z=26
from the latin alphabet. Find the volume of water each pool can hold.
You have to output the volume of water that the pool can hold. Outside the pool the height is 0, so no water is held on the cells at the edge of the pool. The water does not leak diagonally.
Test cases
ZZZZZZZZZZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZAAAAAAAAZ
ZZZZZZZZZZ
OR
[[26, 26, 26, 26, 26, 26, 26, 26, 26, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 1, 1, 1, 1, 1, 1, 1, 1, 26], [26, 26, 26, 26, 26, 26, 26, 26, 26, 26]]
->
1600
ZZZZZZZZZZ
ZRRRRRRRRZ
ZRRRRRRRRZ
ZRRRRRRRRZ
ZFFFFFFFFZ
ZDDDDDDDDZ
ZDDDDDDDDZ
ZDDDDDDDDZ
ZDDDDDDDDZ
ZZZZZZZZZZ
OR
[[26, 26, 26, 26, 26, 26, 26, 26, 26, 26], [26, 18, 18, 18, 18, 18, 18, 18, 18, 26], [26, 18, 18, 18, 18, 18, 18, 18, 18, 26], [26, 18, 18, 18, 18, 18, 18, 18, 18, 26], [26, 6, 6, 6, 6, 6, 6, 6, 6, 26], [26, 4, 4, 4, 4, 4, 4, 4, 4, 26], [26, 4, 4, 4, 4, 4, 4, 4, 4, 26], [26, 4, 4, 4, 4, 4, 4, 4, 4, 26], [26, 4, 4, 4, 4, 4, 4, 4, 4, 26], [26, 26, 26, 26, 26, 26, 26, 26, 26, 26]]
->
1056
XXXXXXXXXX
XSSSSRAAAX
XSSSSRAAAX
XSSSSRAAAX
XXXXXCXXXX
XSSSSCBBBX
XSSSSCBBBX
RSSSSCBBBX
XSSSSCBBBX
XXXXXXXXXX
OR
[[24, 24, 24, 24, 24, 24, 24, 24, 24, 24], [24, 19, 19, 19, 19, 18, 1, 1, 1, 24], [24, 19, 19, 19, 19, 18, 1, 1, 1, 24], [24, 19, 19, 19, 19, 18, 1, 1, 1, 24], [24, 24, 24, 24, 24, 3, 24, 24, 24, 24], [24, 19, 19, 19, 19, 3, 2, 2, 2, 24], [24, 19, 19, 19, 19, 3, 2, 2, 2, 24], [18, 19, 19, 19, 19, 3, 2, 2, 2, 24], [24, 19, 19, 19, 19, 3, 2, 2, 2, 24], [24, 24, 24, 24, 24, 24, 24, 24, 24, 24]]
->
449
ZZZZZZZZZZ
RAAAAZEEEZ
RAAAAZEEEZ
RAAAAZEEEZ
RAAAAZEEEZ
RAAAAAEEEZ
RAAAAZEEEZ
RAAAAZEEEZ
QAAAAZEEEZ
ZZZZZZZZZZ
OR
[[26, 26, 26, 26, 26, 26, 26, 26, 26, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [18, 1, 1, 1, 1, 1, 5, 5, 5, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [18, 1, 1, 1, 1, 26, 5, 5, 5, 26], [17, 1, 1, 1, 1, 26, 5, 5, 5, 26], [26, 26, 26, 26, 26, 26, 26, 26, 26, 26]]
->
816
The input is in the form of a 2D list of integers. The one with letters is just a reference (You can input it as letters if you want to)
Worked Example:
For the 1st test case:
There is only 1 box and that is 10 lines of 26
or A
's, and since this a pool, the A
, represents the bottom of the pool, and the Z
is the top, so 26-1=25
is the depth of the entire pool. Take 25*8*8=1600
, as the Z
is the wall so only a 8*8
area is occupied.
Test Case 3 has a R
in the outer row of X
, so do take note the water level cannot go past this
Test Case 4:
The lowest wall is Q
, so we take 17-1=16
as the highest water level for maximum height of A=1
. We take 16*4*8=512
, next there is a Z
wall, BUT there is an A
breaking through the wall, which is connecting all the E
to the wall of height 16
, so the max height of the water level of E
is 17-5=12
, and take 12*3*8=288
. Finally, we take 512+12+288=816
(12 comes from the extra A
inside the Z
wall)
Tips:
Think of this challenge as water held in many different boxes inside a large box
Others:
- You may assume that all inputs are from the alphabet and that they are all uppercase
- You may assume that the outer row of alphabets do not always have the highest height, and can all have different heights
- The outer row MUST have a higher level than the 2nd outermost row due to the rule of no overflowing
- Water level cannot be higher than the highest "wall"
Scoring
This is code-golf, so shortest code wins!
Credits to the codingame community for this puzzle! Puzzle link