Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Calculating the number of possibilities here actually has an incredibly neat solution (in my opinion).</p> <p>Notice that for n notes, the number of possible connections ( <code>C(n)</code> ) if the first note is connected to the second is <code>C(n-2)</code>. Otherwise it is <code>C(n-1)</code>. This means that</p> <pre><code>C(n) = C(n-1) + C(n-2) C(1) = 3 //Either the first and second are connected, //neither are connected, or the end is connected. C(0) = 2 //Either the end is connected or it isn't </code></pre> <p><strong>Note:</strong> If the last note in a single note example can be connected "to itself" G(0) is 1 Otherwise, it is 0. In addition I am unclear whether <code>E-E</code> and <code>E E-</code> are separate, if they aren't then, <code>C(1)</code> is 2 not 3. Note these only apply for sequences of 0 or 1 <strong>on their own</strong> you'd have to have an if statement outside of the actual function <code>C(n)</code> to return 1 instead of 2. Otherwise it screws up the whole recurrence. A bit messy, but that's the nature of real world data in algorithms</p> <p>This means you've basically got a variant on the fibonacci series! Cool right? </p> <p><strong>Data Representation</strong></p> <p>I would have a list of n <code>boolean</code>s. An array would work fine. If 2 notes are connected, then that entry in the array should be <code>true</code>. I would have index 0 be the connection be the first and second notes, and index <code>n-1</code> be whether or not the last note is connected to anything.</p> <p><strong>Permutation Generation</strong></p> <p>The way in which we calculate the total number of possibilities lends itself nicely to a generation method (<code>G(n)</code>). For n we need to tack on <code>E-E</code> to <code>G(n-2)</code> and <code>E</code> to <code>G(n-1)</code>.</p> <p>At the base of this recurrence we have:</p> <pre><code>G(0) = {E, E-} G(1) = {E-E, E E, E E-} </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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