Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you say its not homework, and I'm a trusting fellow...</p> <ol> <li><p>Build a new array of variable-operator combinations by running each variable against the operator array => ["a+", "a-", "a*", "a/", "b+" ... "d/"]. We'll call this BuiltArray1</p></li> <li><p>Run this array against the operators, outputing each and also storing each in a new array => ["a+a", "a+b", "a+c", "a+d", "a-a" ..."d/d"]. We'll call this BuiltArray2. We can delete the original variable array ["a, "b", "c", "d"] now if we care to - we won't use it again.</p></li> <li><p>Now things get more fun... now we are building BuiltArray3. Run each item in BuiltArray1 against each item in BuiltArray2, outputting each and storing each in BuiltArray3 => ["a+a+a", "a-a+a", "a*a+a", "a/a+a", "b+a+a" ... "d/d/d"]. We can now delete BuiltArray2 to save some memory (this will start to consume memory quickly!)</p></li> <li><p>For BuiltArray4 until our computer dies screaming on the last BuiltArray_n it can handle, we run each item in BuiltArray1 against the previously built array, outputting and also storing each result in a new array, then deleting the previous array.</p></li> </ol> <p>This will chew through memory and processing power, but I can't think of anything more graceful off of the top of my head. </p> <p>Hope it helps.</p> <hr> <p>Here's Ruby codez:</p> <pre><code>@arr1 = ["a", "b", "c", "d"] arr2 = ["+", "-", "*", "/"] @base = [] @arr1.each do |char| arr2.each do |op| @base &lt;&lt; char + op end end @right_vals = @arr1 loop do @new_values = [] @base.each do |left| @right_vals.each do |right| val = left + right puts val @new_values &lt;&lt; val end end @right_vals = @new_values end </code></pre>
 

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