Sailors, coconuts and a monkey problem: Difference between revisions
Content added Content deleted
Line 1,953: | Line 1,953: | ||
0 OK, 0:127</pre> |
0 OK, 0:127</pre> |
||
=={{header|VBA}}== |
|||
<lang vb>Option Explicit |
|||
Public Sub coconuts() |
|||
Dim sailors As Integer |
|||
Dim share As Long |
|||
Dim finalshare As Integer |
|||
Dim minimum As Long, pile As Long |
|||
Dim i As Long, j As Integer |
|||
Debug.Print "Sailors", "Pile", "Final share" |
|||
For sailors = 2 To 6 |
|||
i = 1 |
|||
Do While True |
|||
pile = i |
|||
For j = 1 To sailors |
|||
If (pile - 1) Mod sailors <> 0 Then Exit For |
|||
share = (pile - 1) / sailors |
|||
pile = pile - share - 1 |
|||
Next j |
|||
If j > sailors Then |
|||
If share Mod sailors = 0 And share > 0 Then |
|||
minimum = i |
|||
finalshare = pile / sailors |
|||
Exit Do |
|||
End If |
|||
End If |
|||
i = i + 1 |
|||
Loop |
|||
Debug.Print sailors, minimum, finalshare |
|||
Next sailors |
|||
End Sub</lang>{{out}} |
|||
<pre>Sailors Pile Final share |
|||
2 11 1 |
|||
3 25 2 |
|||
4 765 60 |
|||
5 3121 204 |
|||
6 233275 13020 </pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Python}} |
{{trans|Python}} |