Josephus problem: Difference between revisions
m
→{{header|R}}: Syntax highlighting.
ReeceGoding (talk | contribs) m (→Iterative solution: Shortened link.) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 3,513:
=={{header|R}}==
===Growing circle solution===
<lang
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
{
prisoners<-0:(n-1)
|