# Some problem with function, operator, and optimization.

Actually, this problem come from a programming language challenge.

The objective is: to create a one-to-one function, $f$, that mapped A into B with
A = {0, 1, 2, 3, 4, 5, 6}, and
B = {1, 5, 10, 50, 100, 500, 1000}
and the definition of the function is limited to these operator.


╔═══════════╦════════════════════════════════════╗
║ Operators ║              Function              ║
╠═══════════╬════════════════════════════════════╣
║ []        ║ Bit reference                      ║
║ **        ║ Exponentiation                     ║
║ *, /, %   ║ Multiplication, division, modulus. ║
║ +, -      ║ Addition, subtraction.             ║
║ <<, >>    ║ Left-shift, right-shift.           ║
║ &         ║ Bitwise AND.                       ║
║ |, ^      ║ Bitwise OR, Bitwise XOR.           ║
╚═══════════╩════════════════════════════════════╝


Operators in descdending order of precedence

Here I want to use as little as possible operator in the function definition.

My solution is:

f(x) = (5 << 85[x]) * 10**((x - 1) / 2)


and f that I get is: {(0, 1), (1, 5), (2, 10), (3, 50), (4, 100), (5, 500), (6, 1000)}

Note:
85[x] means the (x+1)-th digit of the binary representation of 85 ($1010101_2$) that is 85[0] = 1, 85[1] = 0, 85[2] = 1, etc. / is an integer division, so 5/2 = 2.

1. My question is, is there a better way to define f, such that the operator that used in the function is as little as possible?
2. Is there a mathematic concept that related to this operator optimization problem that can I use to model/solve it?
-
Is it assumed that all data types are integers, and that division is integer division, so that 11 / 4 = 2? –  Patrick87 Jan 27 '12 at 16:54
Yes, / is integer division. –  Mas Adit Jan 27 '12 at 16:59