Friday, May 31, 2013
Friday, May 24, 2013
Sometimes code can be pretty... and worthless.
It finds an indexed permutation for the list. So each permutation index will give a new permutation... at least until you run out of integers which is at about 12 items.public staticboolean permutation(List values, int index) {
return permutation(values, values.size(), index);
}
private staticboolean permutation(List values, int n, int index) {
if ((index == 0) || (n == 0)) return (index == 0);
Collections.swap(values, n, n-(index % n));
return permutation(values,n-1,index/n);
}
Monday, May 20, 2013
Been a while since I posted.
I blame facebook. Keep posting minorly interesting things there and not here for nobody to see.
Subscribe to:
Posts (Atom)