Hello everyone,<br><br>I am writing some functions that will be made into a class, for doing basic serial operations on cells (i.e. arrays of floats). The operations I have so far are: transpose, reverse, invert, permute, shuffle.
<br><br>The next function to finish is multiply, which does Boulez-style cell multiplication. For the function to work correctly, it should remove any duplicates from the array. Unfortunately, my brain's a little rusty right now. I'm sure I did this in the only computer class I ever took (C++). But I'm too sleepy to figure out the correct solution offhand, I think the ways I'm coming up with are inefficient. Can anyone help? 
<br><br>I've gotten really spoiled, by usually coding these sorts of things in Python, where its amazingly quick to do list manipulations of any kind.<br><br>Here's my code so far, which works except multiply is a dummy function: 
<br><br>//cellFun.ck<br><br>public class Argh<br>{<br>&nbsp; fun static void print(float cell[])<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; for (0 =&gt; int i; i&lt;cell.cap(); i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt;&lt; cell[i] &gt;&gt;&gt; ;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>
<br>&nbsp; fun static void remove (float a[], int index)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; a.cap()-1 =&gt; int newLength;<br>&nbsp;&nbsp;&nbsp; float temp[newLength];<br>&nbsp;&nbsp;&nbsp; for (0 =&gt; int i; i &lt; newLength; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (i&lt;index)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[i] =&gt; temp[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a[i+1] =&gt; temp[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; float a[newLength];<br>&nbsp;&nbsp;&nbsp; for (0 =&gt; int i; i &lt; newLength; i++ )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp[i] =&gt; a[i];
<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; //match<br>&nbsp; fun static int match(float cell[], float element)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; cell.cap() =&gt; int length;<br>&nbsp;&nbsp;&nbsp; -1 =&gt; int position;<br>&nbsp;&nbsp;&nbsp; for (0 =&gt; int i; i&lt;length; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (cell[i] == element)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i =&gt; position;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return position;<br>&nbsp; }<br><br>}<br><br>fun float[] copyCell(float cell[])<br>{<br>&nbsp; cell.cap() =&gt; int length;<br>&nbsp; float newCell[length];
<br>&nbsp; for (0 =&gt; int i; i&lt;length; i++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; cell[i] =&gt; newCell[i];<br>&nbsp; }<br>&nbsp; return (newCell);<br>}<br><br><br>//transpose<br>fun float[] tranCell(float cell[], float amount)<br>{<br>&nbsp; cell.cap() =&gt; int length;
<br>&nbsp; float newCell[length];<br>&nbsp; for (0 =&gt; int i; i&lt;length; i++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; cell[i] + amount =&gt; newCell[i];<br>&nbsp; }<br>&nbsp; return(newCell);<br>}<br><br>//reverse<br>fun float[] revCell(float cell[])<br>{<br>&nbsp; cell.cap
() =&gt; int length;<br>&nbsp; float newCell[length];<br>&nbsp; length - 1 =&gt; int counter;<br>&nbsp; for (0 =&gt; int i; i&lt;length; i++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; cell[i]=&gt; newCell[counter];<br>&nbsp;&nbsp;&nbsp; counter--;<br>&nbsp; }<br>&nbsp; return(newCell);<br>
}<br><br>//invert()<br><br>fun float[] invCell(float cell[])<br>{<br>&nbsp; cell.cap() =&gt; int length;<br>&nbsp; float newCell[length];<br>&nbsp; cell[0] =&gt; newCell[0];<br>&nbsp; for (1 =&gt; int i; i&lt;length; i++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; (2 * cell[0]) - (cell[i]) =&gt; newCell[i];
<br>&nbsp; }<br>&nbsp; return(newCell);<br>}<br><br><br>//shufCell(): <br><br>fun float[] shufCell(float cell[])<br>{<br>&nbsp; cell.cap() =&gt; int length;<br>&nbsp; copyCell(cell) @=&gt; float newCell[];<br>&nbsp; //--- Shuffle elements by randomly exchanging each with one other.
<br>&nbsp; for (0 =&gt; int i; i&lt;length; i++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; std.rand2(0,length-1) =&gt; int r;&nbsp; // generate a random position<br>&nbsp;&nbsp;&nbsp; newCell[i] =&gt; float temp; <br>&nbsp;&nbsp;&nbsp; newCell[r] =&gt; newCell[i]; <br>&nbsp;&nbsp;&nbsp; temp =&gt; newCell[r];
<br>&nbsp; }<br>&nbsp; return(newCell);<br>}<br><br><br>//permCell(float cell[], int amount):<br><br>fun float[] permCell (float cell[], int amount)<br>{<br>&nbsp; cell.cap() =&gt; int length;<br>&nbsp; float newCell[length];<br>&nbsp; for (0=&gt;int i; i&lt;length; i++)
<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; cell[(amount+i)%length] =&gt; newCell[i];<br>&nbsp; }<br>&nbsp; return(newCell);<br>}<br><br>//multiply(float cell[], float multCell[])<br>//unfinished<br>//look for a match<br>//store the position in a new array<br>
<br>fun float[] multCell (float cell[], float mult[])<br>{<br>&nbsp; &lt;&lt;&lt;&quot;unfinished&quot;&gt;&gt;&gt;;<br>&nbsp; return [0.0];<br>}<br><br>//tests!!!<br><br>fun void testShiz()<br>{<br>&nbsp; [0.0,2.0,4.0,6.0,8.0,2.0,10.0] @=&gt; float testCell[];
<br>&nbsp; copyCell(testCell) @=&gt; float theCopy[];<br>&nbsp; [0.0,1.0,2.0] @=&gt; float multi[];<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;print cell&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(testCell);<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;match (return position of first occurrance of 
2.0 in cell)&quot;&gt;&gt;&gt;;<br>&nbsp; &lt;&lt;&lt;Argh.match(testCell,2.0)&gt;&gt;&gt;;<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;transpose cell by 2.0 (returns a copy)&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(tranCell(testCell, 2.0));<br>&nbsp; 
<br>&nbsp; &lt;&lt;&lt;&quot;reverse cell (returns a copy)&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(revCell(testCell));<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;invert cell (returns a copy)&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(invCell(testCell));
<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;shuffle cell (returns a copy)&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(shufCell(testCell));<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;permCell(permute by 2, returns a copy)&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(permCell(testCell, 2)); 
<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;multCell (multiply by [0.0,1.0,2.0], returns a copy&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print(multCell(testCell,multi));<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;print the original&quot;&gt;&gt;&gt;;<br>&nbsp; Argh.print
(testCell);<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;permute the original by 2 and print&quot;&gt;&gt;&gt;;<br>&nbsp; permCell(testCell, 2) @=&gt; testCell;<br>&nbsp; Argh.print(testCell);<br>&nbsp; <br>&nbsp; &lt;&lt;&lt;&quot;print the copy&quot;&gt;&gt;&gt;;
<br>&nbsp; Argh.print(theCopy);<br>}<br><br>testShiz();<br><br>