4 ms·
Modular arithmetic can work, but you need to be a little bit careful. If you want a number from 0-10 then modulo 11 works perfectly (as long as you pick a numb
by Cogito 5y ago
Modular arithmetic can work, but you need to be a little bit careful.
If you want a number from 0-10 then modulo 11 works perfectly (as long as you pick a number well outside any 11 times table you have memorised). This is because it's relatively easy to pick a number without immediately knowing what the mod 11 version of it will be.
For 1-10 you could do mod 10, but that's too easy to cheat. Instead you can take you initial guess n, and multiply (n mod 5) + 1 by (n mod 2) + 1. For example 42 -> ((42 mod 5) + 1) x ((42 mod 2) + 1) = 3 x 1 = 3; 43 -> 4 x 2 = 8.
This second scheme works because we're using a factorisation of the length of our intial range of guesses, and then multiplying the answers. We add 1 because 0s make multiplying boring (and we want 1-10 in any case).
There will still be bias, especially if you've used the scheme before. With the mod5 mod2 scheme the biggest bias is that you only get a 1 if the original guess is congruent to 0 mod 10. A way to avoid that bias, which unfortunately introduces another bias, is to do a two modulo steps. Start with a biggish number, and then do your final one. This is harder to do in your head and makes some final guesses more likely, but only a bit.
So for example, do final guess = (n mod 19) mod 10 + 1. 19 is easyish to calculated because you find the closest multiple of 20, workout that mod 19, and add any leftovers to it. 42 mod 19 = 40 mod 19 + 2 = 2 + 2 = 4
(42 mod 19) mod 10 + 1 = 4 mod 10 + 1 = 5
- unholiness 5y agoYour second scheme with mod2 and 5 is still only sensitive to the last digit though.
- Cogito 5y agoAhh you’re of course correct, might still be useful if you don’t memorise the mapping. I should have gone with my gut and generated the first 100 with each scheme to look at what the distribution looks like. Mod 19 scheme feels like it should be decent but it gives 10 half the probability of any other number. I did find a quick fix that may still be simple enough: take the number mod 19, and add the last digit of the original number. Now take the last digit of the sum, and add 1. So new guess = 1 + (n mod 19 + n mod 10) mod 10. Doing a quick simulation there is no obvious bias.