#include <stdio.h>
#define N_RANGE (5) /* 0 .. N_RANGE */
#define N_SUM (7)
#define N_HIST (N_RANGE * N_SUM + 1)
#define N_HIST2 (N_SUM)
int main(void)
{
int cnt[N_SUM] = { 0 };
int hist[N_HIST] = { 0 };
int hist2[N_HIST2] = { 0 };
int loop = 1;
int i;
while (loop) {
int sum = 0;
for (i=0; i<N_SUM; i++) {
sum += cnt[i];
}
hist[sum]++;
hist2[sum % N_SUM]++;
for (i=0; i<N_SUM; i++) {
int pre = cnt[i];
cnt[i] = (cnt[i] + 1) % (N_RANGE+1);
if (pre > cnt[i]) {
if (i==N_SUM-1) {
loop = 0;
}
} else {
break;
}
}
}
for (i=0; i<N_HIST; i++) {
printf("hist:%d = %d\n", i, hist[i]);
}
for (i=0; i<N_HIST2; i++) {
printf("hist2:%d = %d\n", i, hist2[i]);
}
return 0;
}