Jump to content

Water collected between towers: Difference between revisions

Added uBasic/4tH version
(added RPL)
imported>Thebeez
(Added uBasic/4tH version)
Line 1,127:
</pre>
 
==={{header|uBasic/4tH}}===
{{Trans|GW-BASIC}}
<syntaxhighlight lang="basic">Dim @t(20)
k = 1
 
Proc _getWater (1, 5, 3, 7, 2)
Proc _getWater (5, 3, 7, 2, 6, 4, 5, 9, 1, 2)
Proc _getWater (2, 6, 3, 5, 2, 8, 1, 4, 2, 2, 5, 3, 5, 7, 4, 1)
Proc _getWater (5, 5, 5, 5)
Proc _getWater (5, 6, 7, 8)
Proc _getWater (8, 7, 7, 6)
Proc _getWater (6, 7, 10, 7, 6)
End
 
_getWater
Local (2)
 
w = 0
a@ = Used()
 
For b@ = a@ - 1 To 0 Step -1
@t(b@) = Pop()
Next
 
Do While FUNC(_netWater (a@)) > 1 : Loop
 
Print "Block ";k;" holds ";w;" water units." : k = k + 1
Return
 
_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:278</pre>
==={{header|Visual Basic .NET}}===
====Version 1====
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.