User talk:MichaelChrisco: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 195: | Line 195: | ||
</lang> |
</lang> |
||
Its a work in progress. So if you are lisp savvy, try it out and tell me what you get..... |
Its a work in progress. So if you are lisp savvy, try it out and tell me what you get..... |
||
== Javascript / HTML bean sort demo == |
|||
Hello! I decided to attempt to implement this sort on my own, and added a display system |
|||
to see the process in two steps. |
|||
The demo page for this is here -> [http://betagammaepsilon.com/misc/beans.html] |
|||
(http://betagammaepsilon.com/misc/beans.html) |
|||
but here is the main code for the distribution and sort |
|||
<lang> |
|||
//global bank array |
|||
var data = new Array(); |
|||
function distribute( beans ){ |
|||
// if there are more beans than array slots, |
|||
// make the array longer to accomidate the beans |
|||
// if we don't have any beans, start our array with |
|||
// the first number |
|||
if ( data.length == 0 ){ |
|||
temp = new Array(); |
|||
for(i = 0; i < beans; i++){ |
|||
temp[i] = 0; |
|||
} |
|||
data = temp; |
|||
}else{ |
|||
// if a bean has more rows than our bank, add more rows |
|||
if ( beans > data.length ){ |
|||
//increase array by data.length + beans |
|||
temp = new Array(); |
|||
for(i = 0; i < beans; i++){ |
|||
if(i < data.length){ |
|||
temp[i] = data[i]; |
|||
}else{ |
|||
temp[i] = 0; // start the row with one bean |
|||
} |
|||
} |
|||
// swap the arrays |
|||
data = temp; |
|||
} |
|||
} |
|||
// now distrubute the beans |
|||
// add 1 to each row of beans that our number adds to |
|||
// example: 3 would add 1 bean to the first three rows |
|||
for(i = 0; i < beans; i++){ |
|||
data[i] = parseInt(data[i]) + 1; |
|||
} |
|||
} |
|||
// this function will add an array of numbers to the "bank" |
|||
function beanSort( list ){ |
|||
data = new Array(); // clear list |
|||
for(a = 0; a < list.length; a++){ |
|||
distribute(list[a]); // add bean to the bank |
|||
} |
|||
} |
|||
// Example useage |
|||
var sample = new Array(1,4,3,10,6); |
|||
beanSort(sample); // adds sample to bank, stored in data |
|||
beanSort(data); // sorts the data in the bank |
|||
// an alert(data) would show the final sorted array |
|||
</lang> |
|||
-Jeff Blanchette |
|||
== Sorry for missing you in IRC == |
== Sorry for missing you in IRC == |