Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Josephus-problem/PureBasic/josephus-problem.basic
Normal file
34
Task/Josephus-problem/PureBasic/josephus-problem.basic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
NewList prisoners.i()
|
||||
|
||||
Procedure f2l(List p.i())
|
||||
FirstElement(p()) : tmp.i=p()
|
||||
DeleteElement(p(),1) : LastElement(p())
|
||||
AddElement(p()) : p()=tmp
|
||||
EndProcedure
|
||||
|
||||
Procedure l2f(List p.i())
|
||||
LastElement(p()) : tmp.i=p()
|
||||
DeleteElement(p()) : FirstElement(p())
|
||||
InsertElement(p()) : p()=tmp
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
Repeat
|
||||
Print(#LF$+#LF$)
|
||||
Print("Josephus problem - input prisoners : ") : n=Val(Input())
|
||||
If n=0 : Break : EndIf
|
||||
Print(" - input steps : ") : k=Val(Input())
|
||||
Print(" - input survivors : ") : s=Val(Input()) : If s<1 : s=1 : EndIf
|
||||
ClearList(prisoners()) : For i=0 To n-1 : AddElement(prisoners()) : prisoners()=i : Next
|
||||
If n<100 : Print("Executed : ") : EndIf
|
||||
While ListSize(prisoners())>s And n>0 And k>0 And k<n
|
||||
For j=1 To k : f2l(prisoners()) : Next
|
||||
l2f(prisoners()) : FirstElement(prisoners()) : If n<100 : Print(Str(prisoners())+Space(2)) : EndIf
|
||||
DeleteElement(prisoners())
|
||||
Wend
|
||||
Print(#LF$+"Surviving: ")
|
||||
ForEach prisoners()
|
||||
Print(Str(prisoners())+Space(2))
|
||||
Next
|
||||
ForEver
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue