# Get the reflection of numbers

1. Sep 7, 2011

### xeon123

Hi,

I've this board, like shown in attachment, that has 2 rows. Each rows have 4 places. I'm trying to find a general function that gives me the reflection of the numbers.

I've 2 questions, so I put each question in a item.

a) Like shown in case a) of the attachment, If I write the number 1, my function must return the number 4. If I write the number 2, the function must return the number 3. If I write the number 5, must return the number 8, and if I write the number 7, it must return the number 6. And the opposite. If I write the number 4, I'll the number 1, etc...

As you can see, I've divided the card in half, and I'm trying to get the number that is on the opposition position of the card. I'm looking for a general equation, that answers me this for any row of any size. In this example, I've use a row with 4 position, but it could have been 7, 10, 15, etc...

Anyone can help me?

b) On the case b) it's a little different. I'm doing a kind of displacement. If I write the number 1, I'll get the number 3. If I write the number 2, I get the number 4, and the opposite. I'm also looking for a general function that returns me the correspondent value for any size of the row.

Any help?

Thanks,

2. Sep 7, 2011

### xeon123

Here is the attachment.

File size:
16.2 KB
Views:
66
3. Sep 7, 2011

### HallsofIvy

Staff Emeritus
Here's your function for (a): {(1, 4), (2, 3), (4, 1), (3, 2), (5, 8), (6, 7), (8, 5), (7, 6)}.

4. Sep 7, 2011

### xeon123

I was looking for an equation, and not a function full of constants.

I think the answer for a) is

z=rowsize
f(x)=$\underline{x/z}*z+(x\%z+3)\%z$

The $\underline{}$ means floor.

The only problem with this equation is that, when (x%z+3)%z == 0, it gives x-1. For this case I've to create an exception.

Ideally, I would like to find a general equation for all the cases, but it's not possible.

Last edited: Sep 7, 2011
5. Sep 7, 2011

### superg33k

The answer in the first row is 5-the input number:

Put in 1, get out 5-1=4
Put in 2, get out 5-2=3

For the second row its the same but the input numbers are 4 higher

Put in 5, minus 4=1, 5-1=4, plus 4=8
Put in 6, minus 4=2, 5-2=3, plus 4=7

This can be extended to any length row and column.

6. Sep 7, 2011