public static void Main() {
var testData = new[] { Tuple.Create(new[] {4, 2, 2, 3, }, 2),
Tuple.Create(new[] {4, 2, 0, 3, 1, 2, }, 5),
Tuple.Create(new[] {4, 2, 0, }, 0),
Tuple.Create(new[] {0, 4, 2, 0, }, 0),
Tuple.Create(new[] {0, 4, 2, 0, 3, 1, 2, }, 5),
Tuple.Create(new[] {4, 2, 1, 0, 4, 0, 4}, 13),};
foreach (var test in testData) {
Test(test.Item1, test.Item2);
static void Test(int[] data, int expected) {
var result = CalculateWaterAmount(data);
Console.WriteLine($"Expected: {expected} Actual: {result}");
Console.WriteLine(result == expected ? "Passed!" : "Failed!");
static int CalculateWaterAmount(int[] columns) {
var height = columns.Max();
var width = columns.Length;
var matrix = CreateMatrix(width, height);
for (var x = 0; x < width; x++) {
for (var y = 0; y < columns[x]; y++) {
for (var y = 0; y < height; y++) {
var countingWater = false;
for (var x = 0; x < width; x++) {
if (matrix[x, y] == 'x') {
static char[,] CreateMatrix(int width, int height) {
var result = new char[width, height];
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
static void PrintMatrix(char[,] matrix) {
var width = matrix.GetLength(0);
var height = matrix.GetLength(1);
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
Console.Write(matrix[x, y]);