Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Josephus-problem/VBScript/josephus-problem.vb
Normal file
32
Task/Josephus-problem/VBScript/josephus-problem.vb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
Function josephus(n,k,s)
|
||||
Set prisoner = CreateObject("System.Collections.ArrayList")
|
||||
For i = 0 To n - 1
|
||||
prisoner.Add(i)
|
||||
Next
|
||||
index = -1
|
||||
Do Until prisoner.Count = s
|
||||
step_count = 0
|
||||
Do Until step_count = k
|
||||
If index+1 <= prisoner.Count-1 Then
|
||||
index = index+1
|
||||
Else
|
||||
index = (index+1)-(prisoner.Count)
|
||||
End If
|
||||
step_count = step_count+1
|
||||
Loop
|
||||
prisoner.RemoveAt(index)
|
||||
index = index-1
|
||||
Loop
|
||||
For j = 0 To prisoner.Count-1
|
||||
If j < prisoner.Count-1 Then
|
||||
josephus = josephus & prisoner(j) & ","
|
||||
Else
|
||||
josephus = josephus & prisoner(j)
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
'testing the function
|
||||
WScript.StdOut.WriteLine josephus(5,2,1)
|
||||
WScript.StdOut.WriteLine josephus(41,3,1)
|
||||
WScript.StdOut.WriteLine josephus(41,3,3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue