Water collected between towers: Difference between revisions

uBasic/4tH - eliminated a global
imported>Thebeez
(uBasic/4tH - eliminated a global)
 
(3 intermediate revisions by 3 users not shown)
Line 1,126:
City configuration 7 collected 0 units of water.
</pre>
 
==={{header|uBasic/4tH}}===
{{Trans|GW-BASIC}}
<syntaxhighlight lang="basic">Dim @t(20)
 
k = FUNC (_getWater (1, 5, 3, 7, 2, 1))
k = FUNC (_getWater (5, 3, 7, 2, 6, 4, 5, 9, 1, 2, k))
k = FUNC (_getWater (2, 6, 3, 5, 2, 8, 1, 4, 2, 2, 5, 3, 5, 7, 4, 1, k))
k = FUNC (_getWater (5, 5, 5, 5, k))
k = FUNC (_getWater (5, 6, 7, 8, k))
k = FUNC (_getWater (8, 7, 7, 6, k))
k = FUNC (_getWater (6, 7, 10, 7, 6, k))
End
 
_getWater
Param (1)
Local (2)
 
w = 0
c@ = Used()
 
For b@ = c@ - 1 To 0 Step -1
@t(b@) = Pop()
Next
 
Do While FUNC(_netWater (c@)) > 1 : Loop
 
Print "Block ";a@;" holds ";w;" water units."
Return (a@ + 1)
 
_netWater
Param (1)
Local (3)
 
For d@ = a@-1 To 0 Step -1
If @t(d@) Then
If d@ = 0 Then Unloop : Return (0) : fi
Else
Continue
EndIf
 
b@ = 0
 
For c@ = 0 To d@
If @t(c@) > 0 Then
@t(c@) = @t(c@) - 1
b@ = b@ + 1
Else
If b@ > 0 Then w = w + 1 : fi
EndIf
Next
 
Unloop : Return (b@)
Next
Return (0)</syntaxhighlight>
{{Out}}
<pre>Block 1 holds 2 water units.
Block 2 holds 14 water units.
Block 3 holds 35 water units.
Block 4 holds 0 water units.
Block 5 holds 0 water units.
Block 6 holds 0 water units.
Block 7 holds 0 water units.
 
0 OK, 0:409</pre>
 
==={{header|Visual Basic .NET}}===
Line 4,270 ⟶ 4,335:
2 ██████████
1 ██████████ no units of rainwater collected
</pre>
 
=={{header|RPL}}==
{{trans|Python}}
{{works with|HP|49/50}}
« DUPDUP SIZE 1 - NDUPN →LIST
DUP 1 « 1 NSUB SUB 0 + « MAX » STREAM » DOSUBS 0 SWAP + <span style="color:grey">@ the seq of max heights to the left of each tower</span>
SWAP 1 « NSUB 1 + OVER SIZE SUB 0 + « MAX » STREAM » DOSUBS 0 + <span style="color:grey">@ the seq of max heights to the right of each tower</span>
MIN SWAP -
1 « 0 MAX » DOLIST ∑LIST
» '<span style="color:blue">WATER</span>' STO
« { {1 5 3 7 2}
{5 3 7 2 6 4 5 9 1 2}
{2 6 3 5 2 8 1 4 2 2 5 3 5 7 4 1}
{5 5 5 5}
{5 6 7 8}
{8 7 7 6}
{6 7 10 7 6} }
1 « <span style="color:blue">WATER</span> » DOLIST
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 2 14 35 0 0 0 0 }
</pre>
 
Line 4,616 ⟶ 4,705:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Math, Nums
import "./fmt" for Fmt
 
var waterCollected = Fn.new { |tower|
Anonymous user