Author | Message |
---|---|
rabbott
Posts: 1649
|
Posted 11:10 Feb 06, 2014 |
If you represent the numbers in the multiplication game to the base 18, it becomes clearer which will win and lose. My worksheet now shows numbers followed by the number-base-18 in parentheses, e.g. 18(10). The winning and losing ranges for the first player are as follows wins [2(2) - 9(9)]; loses [10(a) - 18(10)] (Note I'm using 'a' for 10 to the base 18.) wins [19(11) - 162(90]); loses [163(91) - 324(100)] wins [325(101) - 2916(900)]; loses [2917(901) - 5832(1000)] In general: wins: [18^n+1 - 18^n*9]; loses: [18^n*9+1 - 18^(n+1)] or wins: [10 ... 01 - 90...0]; loses: [90 ... 1 - 100 ... 0] This works because a player with a number in a winning range (18^n+1 - 18^n*9) can always leave the next player with a number in a losing range (18^n*9+1 - 18^(n+1)). Similarly a player with a number in a losing range (18^n*9+1 - 18^(n+1)) must leave the next player with a number in a winning range (18^(n+1)+1 - 18^(n+1)*9). So, an algorithm to determine which player wins is as follows. if (target<= 18) { if (target <= 9) player 1 wins else player 2 wins} else { val firstTwoDigits = the first two digits of target when represented to the base 18 if (firstTwoDigits are in the range 11 - 90) player 1 wins else /* firstTwoDigits are either in the range 91-99 or are 10 */ player 2 wins } This is essentially Daniel's algorithm. Last edited by rabbott at
11:14 Feb 06, 2014.
|