Me and a friend are mulling over an **interesting** Computer Science question.

You have a simple **2D Array**:

```
[ 1, 2, 3, 4 ]
[ 5, 6, 7, 8 ]
[ 9, 10, 11, 12 ]
[ 13, 14, 15, 16 ]
```

Now take this array and **shuffle all the elements** in the array:

```
[ 11, 5, 14, 10 ]
[ 8, 2, 4, 16 ]
[ 15, 1, 3, 13 ]
[ 6, 12, 9, 7 ]
```

A fairly simple concept at first. However, what if we take it **one more step**? Now, **shuffle the original array** such that *no* elements of the new array are next to an item they were adjacent to in the **original array** in a cardinal direction.

Our first shuffle **fails** as 1 is next to 2 and was also next to 2 in the original array.

Here is a **working** example:

```
[ 7, 16, 13, 2 ]
[ 14, 3, 5, 8 ]
[ 9, 1, 4, 11 ]
[ 12, 10, 15, 6 ]
```

Still not *too* bad. Now to the **real** question!

Shuffle the **original array** again such that *no* elements of the array are next to an element they were adjacent to in either cardinal directions **or via diagonals**.

Our working example **fails** since 1 is next to 5 diagonally and was next to 5 in the original array.

## Some Thoughts:

- Can an array even be determined?
- Does it depend on the size of the array?
- Does the array need to be symmetrical?
- Does the array need to have an even / odd amount of elements?
- Does a solution hold for all arrays of size
**M**by**N**? - If there exists a solution, what would be the running time to find the new array?

What do you think?

**EDIT**

I am surprised to find my question closed as "off topic". According to the FAQ if my question "...generally covers a specific programming problem..." then it is allowed to be asked and is not "off-topic".

The bottom-line question I was asking is:

"Can you take a 2D array and shuffle it so no members will be next to each other in the new array, including diagonals".

Is that not a good programming question? I feel strongly my question should not be closed.

notwrap around the left/right and top/bottom, given the (2,6) pair as an example.