RosettaCodeData/Task/Josephus-problem/Frink/josephus-problem.frink

22 lines
726 B
Plaintext

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