Hello everyone,
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.
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?
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.
Here's my code so far, which works except multiply is a dummy function:
//cellFun.ck
public class Argh
{
fun static void print(float cell[])
{
for (0 => int i; i>> ;
}
}
fun static void remove (float a[], int index)
{
a.cap()-1 => int newLength;
float temp[newLength];
for (0 => int i; i < newLength; i++)
{
if (i temp[i];
}
else
{
a[i+1] => temp[i];
}
}
float a[newLength];
for (0 => int i; i < newLength; i++ )
{
temp[i] => a[i];
}
}
//match
fun static int match(float cell[], float element)
{
cell.cap() => int length;
-1 => int position;
for (0 => int i; i position;
break;
}
}
return position;
}
}
fun float[] copyCell(float cell[])
{
cell.cap() => int length;
float newCell[length];
for (0 => int i; i newCell[i];
}
return (newCell);
}
//transpose
fun float[] tranCell(float cell[], float amount)
{
cell.cap() => int length;
float newCell[length];
for (0 => int i; i newCell[i];
}
return(newCell);
}
//reverse
fun float[] revCell(float cell[])
{
cell.cap() => int length;
float newCell[length];
length - 1 => int counter;
for (0 => int i; i newCell[counter];
counter--;
}
return(newCell);
}
//invert()
fun float[] invCell(float cell[])
{
cell.cap() => int length;
float newCell[length];
cell[0] => newCell[0];
for (1 => int i; i newCell[i];
}
return(newCell);
}
//shufCell():
fun float[] shufCell(float cell[])
{
cell.cap() => int length;
copyCell(cell) @=> float newCell[];
//--- Shuffle elements by randomly exchanging each with one other.
for (0 => int i; i int r; // generate a random position
newCell[i] => float temp;
newCell[r] => newCell[i];
temp => newCell[r];
}
return(newCell);
}
//permCell(float cell[], int amount):
fun float[] permCell (float cell[], int amount)
{
cell.cap() => int length;
float newCell[length];
for (0=>int i; i newCell[i];
}
return(newCell);
}
//multiply(float cell[], float multCell[])
//unfinished
//look for a match
//store the position in a new array
fun float[] multCell (float cell[], float mult[])
{
<<<"unfinished">>>;
return [0.0];
}
//tests!!!
fun void testShiz()
{
[0.0,2.0,4.0,6.0,8.0,2.0,10.0] @=> float testCell[];
copyCell(testCell) @=> float theCopy[];
[0.0,1.0,2.0] @=> float multi[];
<<<"print cell">>>;
Argh.print(testCell);
<<<"match (return position of first occurrance of 2.0 in cell)">>>;
<<>>;
<<<"transpose cell by 2.0 (returns a copy)">>>;
Argh.print(tranCell(testCell, 2.0));
<<<"reverse cell (returns a copy)">>>;
Argh.print(revCell(testCell));
<<<"invert cell (returns a copy)">>>;
Argh.print(invCell(testCell));
<<<"shuffle cell (returns a copy)">>>;
Argh.print(shufCell(testCell));
<<<"permCell(permute by 2, returns a copy)">>>;
Argh.print(permCell(testCell, 2));
<<<"multCell (multiply by [0.0,1.0,2.0], returns a copy">>>;
Argh.print(multCell(testCell,multi));
<<<"print the original">>>;
Argh.print(testCell);
<<<"permute the original by 2 and print">>>;
permCell(testCell, 2) @=> testCell;
Argh.print(testCell);
<<<"print the copy">>>;
Argh.print(theCopy);
}
testShiz();