Problem #90

The Cantor ternary function, 
F : [0,1] -> [0,1] 
is defined as follows:
- Express x in base 3. If possible, use no 1s. (This makes a 
difference only if the expansion ends in 022222... = 100000... or 
200000... = 122222...)
 - Replace the first 1 with a 2 and everything after it with 0.
 - Replace all 2s with 1s.
 - Interpret the result as a binary number. The result is 
F(x).
 
A graph of the Cantor function is shown below.
This month's problem is to evaluate
For n = 1,2, and 3. Can you find a formula for arbitrary 
n?