Water collected between towers: Difference between revisions
→{{header|Visual Basic .NET}}: simplified water tower array (wta) declaration, streamlined code to take advantage of preset sub-array lengths.
(Added vb.Net program, features erosion of strings method instead of tower height comparison method,) |
(→{{header|Visual Basic .NET}}: simplified water tower array (wta) declaration, streamlined code to take advantage of preset sub-array lengths.) |
||
Line 1,198:
Sub Main()
Dim shoTow As Boolean = Environment.GetCommandLineArgs().Count > 1 ' Show towers.
Dim wta
New Integer() {1, 5, 3, 7, 2}, New
New
New
New
Dim blk As String, ' String representation of a block of towers.
lf As String = vbCrLf
For i As Integer = 0 To UBound(wta
Dim
blk = ""
Do
For j As Integer = 0 To
If wta(i
blk &= "B" : wta(i
Else ' Empty space detected, fill if not first or last column.
' Periods are possible water retention cells.
blk &= If(j > 0 AndAlso j <
End If
Next
If
Loop Until bpl = 0
' Now erode potential water retention cells from left and right
While blk.Contains(" .") : blk = Replace(blk, " .", " ") : End While
Line 1,234 ⟶ 1,225:
' Optionally show towers w/ water marks.
If shoTow Then Console.WriteLine(lf & blk)
'
Console.WriteLine("Block {0} retains {1,2} water units.", i + 1,
Len(Replace(Replace(Replace(blk, lf, ""), "B", ""), " ", "")))
|