A function to map [0,1]x[1,3] to [1,8] or [0,7]

106 Views Asked by At

I don't know why I can't figure this out. I'm writing some code, and want to use this "mapping". As I am using arrays, it's not important if the output is 0 through 7, or 1 through 8. I just need the pairs to map correctly.

Also, I'm wondering if the first four should map to odds, and the last 4 to evens, but I don't know. So I'm writing it as I thought it would work.

r $\in (0,1)$, and c $\in (0,3)$

r,c
0,0 $\rightarrow$ 0
0,1 $\rightarrow$ 1
0,2 $\rightarrow$ 2
0,3 $\rightarrow$ 3
1,0 $\rightarrow$ 4
1,1 $\rightarrow$ 5
1,2 $\rightarrow$ 6
1,3 $\rightarrow$ 7

For more clarity it's something like

if r = 0 and c = 0 then fetch index(0) from someArray
if r = 0 and c = 1 then fetch index(1) from someArray
if ...
if r = 1 and c = 3 then fetch index(7) from someArray

where "fetch index(x)" is some $f(r,c) \rightarrow x$

I tried some binary power stuff with the r, and c, but nothing works. e.g. $2^r+c$,   $2^{(r+1)} + (c+1) -2$

What should $f(r,c)$ be?

1

There are 1 best solutions below

1
On BEST ANSWER

Try $f(r,c)=4 r + c$.

$ {}{} $