Thanks, Codeplug. The function works now, but it's very sloppy, and the goal is efficiency (which is why numeric containers were used in the first place). Would inlining or recursion be reasonable here?
Code:
// 5**5 values
void cycle(int balls) {
// Return the next cyclic arrangement of b
valarray<int> state(0, 5); // State of the machine
valarray<int> cake(0, balls*5); // A "cake" with five layers (slices)
for(int b = 0; b < balls; b++) cake[5*b] = 1;
// FORTRAN-style indexing is used: elements are read top to bottom,
// and left to right.
enum Odometer { L2 = 5, L3 = 25, L4 = 125, L5 = 625, LD = 3125};
for(;;) {
static int ct = 0;
ct++;
for(int k = 0; k < balls; k++){
state[k] = valarray<int>(cake[slice(k, 5, 5)]).sum();
cout << state[k] << " ";
}
cout << '\n';
cake[slice(0, 5, 1)] = valarray<int>(cake[slice(0, 5, 1)]).cshift(-1);
if(ct % L2 == 0)
cake[slice(5, 5, 1)] = valarray<int>(cake[slice(5, 5, 1)]).cshift(-1);
if(ct % L3 == 0)
cake[slice(10, 5, 1)] = valarray<int>(cake[slice(10, 5, 1)]).cshift(-1);
if(ct % L4 == 0)
cake[slice(15, 5, 1)] = valarray<int>(cake[slice(15, 5, 1)]).cshift(-1);
if(ct % L5 == 0)
cake[slice(20, 5, 1)] = valarray<int>(cake[slice(20, 5, 1)]).cshift(-1);
if(ct % LD == 0) break;
}
}