Josephus problem: Difference between revisions
Content added Content deleted
m (Updated description and link for Fōrmulæ solution) |
ReeceGoding (talk | contribs) m (→Iterative solution: Shortened link.) |
||
Line 3,525: | Line 3,525: | ||
*It is 1-indexed, meaning that we will have a tough time using most solutions that exploit modular arithmetic. |
*It is 1-indexed, meaning that we will have a tough time using most solutions that exploit modular arithmetic. |
||
*It lacks any concept of a linked list, meaning that we can't take a circular list approach. |
*It lacks any concept of a linked list, meaning that we can't take a circular list approach. |
||
*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 |
*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. |
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 R>josephusProblem<-function(n,k,m) |
<lang R>josephusProblem<-function(n,k,m) |