RosettaCodeData/Task/Josephus-problem/R/josephus-problem-1.r
2023-07-01 13:44:08 -04:00

8 lines
153 B
R

jose <-function(s, r,n){
y <- 0:(r-1)
for (i in (r+1):n)
y <- (y + s) %% i
return(y)
}
> jose(3,1,41) # r is the number of remained prisoner.
[1] 30