PowerShell Programming Praxis: Josephus' Circle
And another PowerShell excersise from the WTF (Worse than Failure) contest Programming Praxis: Josephus' Circle . (for more info see original contest post)
Function get-SafeSpot ($count,$Skip) {
$q = [Collections.queue](1..$count)
while ($q.count -gt 1){
1..($skip-1) |% {$q.enqueue($q.dequeue())}
[void]$q.dequeue()
}
$q
}
By using a Queue (that works on a FIFO (First In First Out) base, I could keep the loop very simple by just requeueing the surviving members) and could save me the Math otherwise involved in keeping count.
Enjoy,
Greetings /\/\o\/\/