Player Wins if # of players is...
1 1, 2, 4, 8, 16
3 3, 5, 9, 17
5 6, 10, 18
7 7, 11, 19
9 12, 20
11 13, 21
13 14, 22
15 15, 23
17 24
19 25
21 26
Some patterns develop....
The last player wins whenever the number of players is a power of 2 minus 1 (3, 7, 15, 31).
Player 1 wins whenever the number of players is a power of 2 (2, 4, 8)
Player 3 wins whenever the number of players is a power of 2 plus 1 (3, 5, 9)
player 5 wins whenever the number of players is a power of 2 plus 2 (6, 10)
Player 7 wins whenever the number of players is a power of 2 plus 3 (7, 11)
... and so on.
So for N players, the winner will be 2 * [N mod 2**X] + 1, where 2**X is the greatest power of 2 that is less than N.
For example, if there are 63 players the answer should be 63 (since 63 is 2**6 - 1). Double checking our formular... 32 is the greatest power of 2 that is less than 63
2 * [N mod 2**X] + 1 = 2 * [63 mod 32] + 1
= 2 * 31 + 1
= 63
For N = 100, it would be 2 * [100 mod 64] + 1 = 2 * 36 + 1 = 73
I haven't look at the 2nd problem yet but I wouldn't be surprised if it's based on the powers of 3.
]]>function INOUT(x){
if(x == 1) then
{
return 1
}
else
{
if (INOUT(x-1) + 2 ≤ x) then
{
return (INOUT(x-1) + 2)
}
else
{
return 1
}
}
}
}
I can't figure out a general formula though. It's gonna bug me now.
]]> Number of children playing | Child who is it
-----------------------------------------------------------------------------------
1 | 1
2 | 1
3 | 3
4 | 1
5 | 3
6 | 5
7 | 7
8 | 1
9 | 3
10 | 5
From that, it looks like the pattern is that it starts at 1 and counts up odd numbers until it reaches the point where the number is the same as the number of children playing and at that point it goes back to 1 and starts again.
So there's the pattern, but I can't think of how you'd make that into a formula.
For the in-in-out format, you get this for the first few:
Number of children playing | Child who is it
-----------------------------------------------------------------------------------
1 | 1
2 | 2
3 | 2
4 | 1
5 | 4
6 | 1
7 | 4
8 | 7
9 | 1
10 | 4
And I can't even see a pattern in that one. It seems to be something to do with 1, 1 4, 1 4 7... but the 2's at the start ruin that theory. I'll try to dig into this more later on. I hope I've helped you a bit though.
]]>What is the formula which will predict who will be it?
And if the children change to "in, in, out........." what would the formula then be?
]]>