Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Josephus-problem/Frink/josephus-problem.frink
Normal file
21
Task/Josephus-problem/Frink/josephus-problem.frink
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
killingCycle[prisonerCount,killStep = 2] :=
|
||||
{
|
||||
i = 0
|
||||
killed = new array
|
||||
prisoners = array[0 to prisonerCount - 1]
|
||||
while length[prisoners] > 1
|
||||
{
|
||||
i = (i + killStep - 1) mod length[prisoners]
|
||||
killed.push[prisoners.remove[i]] // Remove the killed prisoner from the prisoners array and add it to the killed array.
|
||||
}
|
||||
killedResult = "Killed:"
|
||||
for kill = killed // Loop through the killed array to format it nicely.
|
||||
{
|
||||
killedResult = killedResult + " " + kill
|
||||
}
|
||||
aliveResult = "Alive: " + prisoners@0 // Get the only item left in the array
|
||||
return """$killedResult
|
||||
$aliveResult"""
|
||||
}
|
||||
|
||||
println[killingCycle[41,3]] // Enter in total number of prisoners and the number to skip each cycle
|
||||
Loading…
Add table
Add a link
Reference in a new issue