Talk:Josephus problem: Difference between revisions

Content added Content deleted
(→‎Categorisation of solutions: add explanation for Factor solution)
Line 96: Line 96:


--[[User:ReeceGoding|ReeceGoding]] ([[User talk:ReeceGoding|talk]]) 13:02, 24 June 2020 (UTC)
--[[User:ReeceGoding|ReeceGoding]] ([[User talk:ReeceGoding|talk]]) 13:02, 24 June 2020 (UTC)

: The Factor solution is a simple fold/reduce. I'll use the example from the task where n = 41 and k = 3.

: First, create a range of numbers from 1 to 41.
: <code>{ 1 2 3 ... 41 }</code>

: Use 0 as the first element for the fold/reduce.
: <code>{ 0 1 2 3 ... 41 }</code>

: Now we have a 0 and a 1 we need to do something with.

: Add k (which is 3) to 0 so now we have 3 and 1.
: <code>{ 3 1 2 3 ... 41 }</code>

: Take 3 modulo 1 which is zero. This is the result that will be used in the next iteration of the fold/reduce.
: <code>{ 0 2 3 4 ... 41 }</code>

: Now we have 0 and 2. Add 3 to 0, which is 3. Take 3 modulo 2 which is 1.
: <code>{ 1 3 4 5 ... 41 }</code>

: Now we have 1 and 3. Add 3 to 1, which is 4. Take 4 modulo 1 which is 1.
: <code>{ 1 4 5 6 ... 41 }</code>

: etc. Now whichever remainder you end up with via this process is the answer. I didn't write this solution and I'm not familiar with the Josephus problem, so I'm not sure if this fits into one of the categories above. --[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 14:34, 24 June 2020 (UTC)