Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally speaking, when you need to do something recursively it helps to start from the "bottom" and think your way up. Consider: You have a set <code>S</code> of <em>n</em> numbers <code>{a,b,c,...}</code>, and a set of four operations <code>{+,-,*,/}</code>. Let's call your recursive function that operates on the set <code>F(S)</code></p> <ul> <li>If <em>n</em> is 1, then <code>F(S)</code> will just be that number. </li> <li>If <em>n</em> is 2, <code>F(S)</code> can be eight things: <ul> <li>pick your left-hand number from <code>S</code> (2 choices)</li> <li>then pick an operation to apply (4 choices)</li> <li>your right-hand number will be whatever is left in the set</li> </ul></li> <li>Now, you can generalize from the <em>n</em>=2 case: <ul> <li>Pick a number <code>x</code> from <code>S</code> to be the left-hand operand (<em>n</em> choices)</li> <li>Pick an operation to apply</li> <li>your right hand number will be <code>F(S-x)</code></li> </ul></li> </ul> <p>I'll let you take it from here. :) </p> <p>edit: Mark poses a valid criticism; the above method won't get absolutely everything. To fix that problem, you need to think about it in a slightly different way: </p> <ul> <li>At each step, you first pick an operation (4 choices), and then</li> <li><em>partition</em> <code>S</code> into two sets, for the left and right hand operands,</li> <li>and recursively apply <code>F</code> to both partitions</li> </ul> <p>Finding all partitions of a set into 2 parts isn't trivial itself, though. </p>
    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. 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.
 

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