Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramming Theory: Shuffling a 2D Array
    primarykey
    data
    text
    <p>Me and a friend are mulling over an <strong>interesting</strong> Computer Science question.</p> <hr> <p>You have a simple <strong>2D Array</strong>: </p> <pre><code>[ 1, 2, 3, 4 ] [ 5, 6, 7, 8 ] [ 9, 10, 11, 12 ] [ 13, 14, 15, 16 ] </code></pre> <p>Now take this array and <strong>shuffle all the elements</strong> in the array:</p> <pre><code>[ 11, 5, 14, 10 ] [ 8, 2, 4, 16 ] [ 15, 1, 3, 13 ] [ 6, 12, 9, 7 ] </code></pre> <p>A fairly simple concept at first. However, what if we take it <strong>one more step</strong>? Now, <strong>shuffle the original array</strong> such that <em>no</em> elements of the new array are next to an item they were adjacent to in the <strong>original array</strong> in a cardinal direction.</p> <p>Our first shuffle <strong>fails</strong> as 1 is next to 2 and was also next to 2 in the original array.</p> <p>Here is a <strong>working</strong> example:</p> <pre><code>[ 7, 16, 13, 2 ] [ 14, 3, 5, 8 ] [ 9, 1, 4, 11 ] [ 12, 10, 15, 6 ] </code></pre> <p>Still not <em>too</em> bad. Now to the <strong>real</strong> question! </p> <p>Shuffle the <strong>original array</strong> again such that <em>no</em> elements of the array are next to an element they were adjacent to in either cardinal directions <strong>or via diagonals</strong>.</p> <p>Our working example <strong>fails</strong> since 1 is next to 5 diagonally and was next to 5 in the original array.</p> <h2>Some Thoughts:</h2> <ol> <li>Can an array even be determined?</li> <li>Does it depend on the size of the array?</li> <li>Does the array need to be symmetrical?</li> <li>Does the array need to have an even / odd amount of elements?</li> <li>Does a solution hold for all arrays of size <strong>M</strong> by <strong>N</strong>?</li> <li>If there exists a solution, what would be the running time to find the new array?</li> </ol> <p>What do you think?</p> <p><strong>EDIT</strong></p> <p>I am surprised to find my question closed as "off topic". According to the <a href="https://stackoverflow.com/faq">FAQ</a> if my question "...generally covers a specific programming problem..." then it is allowed to be asked and is not "off-topic".</p> <p>The bottom-line question I was asking is:</p> <blockquote> <p>"Can you take a 2D array and shuffle it so no members will be next to each other in the new array, including diagonals".</p> </blockquote> <p>Is that not a good programming question? I feel strongly my question should not be closed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload