Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Josephus-problem/Gambas/josephus-problem.gambas
Normal file
19
Task/Josephus-problem/Gambas/josephus-problem.gambas
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Public Sub Main()
|
||||
|
||||
Dim n As Integer = 41 'prisoners
|
||||
Dim k As Integer = 3 'order of execution
|
||||
|
||||
Print "n = "; n, "k = "; k, "final survivor = "; Josephus(n, k, 0)
|
||||
|
||||
End
|
||||
|
||||
Function Josephus(n As Integer, k As Integer, m As Integer) As Integer
|
||||
|
||||
Dim lm As Integer = m
|
||||
|
||||
For i As Integer = m + 1 To n
|
||||
lm = (lm + k) Mod i
|
||||
Next
|
||||
Return lm
|
||||
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue