My formula used bit wise and &, equality comparison ==, implicit cast of true/false to 1/0 and integer multiplication *, and integer addition +. It should work in C or Javascript or what have you. x is the input, the result is the output. Exactly as you specify it.
This works since the last digits are all unique. By bitwise and with 0xf, we get the last digit of the input and compare with each unique last digit. If equal it will result in 1 times the correct output value otherwise 0. Then summed all together maps them properly.
Any one to one mapping can be done without the bitwise and, using only the other 4 operations. Of course it will only work for individual inputs then and will always be zero for not yet seen numbers. Currently it works for individual input last digits that match and is 0 for all other inputs.
Last edited by chants; 01-14-2020 at 04:44.
|