Given inputs 1-32 how can I generate the below output?
in. out
- 1
- 1
- 1
- 1
- 2
- 2
- 2
- 2
- 1
- 1
- 1
- 1
- 2
- 2
- 2
- 2 ...
Edit Not Homework.. just lack of sleep.
I am working in C#, but I was looking for a language agnostic algorithm.
Edit 2 To provide a bit more background... I have an array of 32 items that represents a two dimensional checkerboard. I needed the last part of this algorithm to convert between the vector and the graph, where the index aligns on the black squares on the checkerboard.
Final Code:
--Index;
int row = Index >> 2;
int col = 2 * Index - (((Index & 0x04) >> 2 == 1) ? 2 : 1);