0
$\begingroup$

I can't find out a function f(x)=y that would map my x's to required y's. It is OK to write it in a programming language. Notation in mathematics is also OK. It must be something simple enough but I can't find a solution.

X:   >>   Y:  1         1 2         1  3         2 4         2  5         4 6         4  7         8 8         8  9         16 10        16  ... 

2 Answers 2

3

So note that the $y$s are powers of 2 and that for $k \in \mathbb N$ the numbers $2k$ and $2k - 1$ are mapped to $2^k$. that is if we divide $x$ by $2$ and round towards the next bigger integer, that is consider $\lceil \frac x2\rceil$, this gives $k$ for both cases. So $f \colon \mathbb N \to \mathbb N$ is given by $ f(x) = 2^{\lceil \frac x2\rceil - 1} $

  • 0
    Thank you, excellent solution!2012-12-07
1

Note that $f(2i-1)=f(2i)=2^{i-1}$ for $i\in\mathbb{N}$. So $f(x)$ can be given by $f(x)=2^{x/2-1}\mbox{ when $x$ is even }$ and $f(x)=2^{(x-1)/2}\mbox { when $x$ is odd }$ for all $x\in\mathbb{N}$

  • 0
    Thanks for suggestion. I've accepted martini's solution since I don't need even/odd checking.2012-12-07