Hello everyone,<br><br>I tried to send this earlier today, and it didn't seem to come through, but in the meantime I did more work on the problem.<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? My attempt at this is in the function remDup below, but I made some mistake, I'm sure relating to using a while loop--I'm not sure what the problem is though, or a better way to do it.<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>//cellFun.ck<br><br>public class Argh<br>{<br> fun static void print(float cell[])<br> {<br> for (0 => int i; i<cell.cap(); i++)<br> {<br> <<< cell[i] >>> ;<br> }<br>
}<br><br> fun static void remove (float a[], int index)<br> {<br> a.cap()-1 => int newLength;<br> float temp[newLength];<br> for (0 => int i; i < newLength; i++)<br> {<br> if (i<index)<br>
{<br> a[i] => temp[i];<br> }<br> else<br> {<br> a[i+1] => temp[i];<br> }<br> }<br> float a[newLength];<br> for (0 => int i; i < newLength; i++ )<br> {<br> temp[i] => a[i];
<br> }<br> }<br><br> //match<br> fun static int match(float cell[], float element)<br> {<br> cell.cap() => int length;<br> -1 => int position;<br> for (0 => int i; i<length; i++)<br> {<br> if (cell[i] == element)
<br> {<br> i => position;<br> break;<br> }<br> }<br> return position;<br> }<br> <br><br><br> fun static float[] copy(float cell[])<br> {<br> cell.cap() => int length;<br> float newCell[length];
<br> for (0 => int i; i<length; i++)<br> {<br> cell[i] => newCell[i];<br> }<br> return (newCell);<br> }<br><br> //sort<br> fun static float[] sort(float cell[])<br> {<br> cell.cap() => int length;
<br> float temp;<br> for (0 => int x ; x < length-1; x++)<br> {<br> for (0 => int y; y < length-x-1; y++)<br> {<br> if (cell[y] > cell[y+1])<br> {<br> cell[y] => temp;
<br> cell[y+1] => cell[y];<br> temp => cell[y+1];<br> }<br> }<br> }<br> return cell;<br> }<br><br> fun static float[] remDup(float cell[])<br> {<br> 1 => int i;<br>
cell.cap() => int length; <br> while (i < length-1)<br> {<br> if (cell[i]==cell[i+1])<br> {<br> remove(cell,i+1);<br> }<br> else<br> {<br> i++;<br> }<br> }<br> return cell;<br> }<br>
<br>}<br><br>