Josephus problem: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
m (→‎Iterative solution: Shortened link.)
m (→‎{{header|R}}: Syntax highlighting.)
Line 3,513:
=={{header|R}}==
===Growing circle solution===
<lang Rrsplus>jose <-function(s, r,n){
y <- 0:(r-1)
for (i in (r+1):n)
Line 3,527:
*The idiomatic way to roll an array in R (e.g. as [[Josephus_problem#Ruby|the Ruby solution]] has) is to exploit the head and tail functions, but those break if we are rolling by more than the length of the array (see https://stackoverflow.com/q/18791212 for a few tricks for this).
Regardless, it is still solvable. The following adapts a great deal of [[Josephus_problem#Lua|the Lua solution]]. The arguments n, k, and m are as in the task description.
<lang Rrsplus>josephusProblem<-function(n,k,m)
{
prisoners<-0:(n-1)
331

edits