So first you want all numbers with digits 0 in order. those. just 00
0,1: 00, 01, 10, 11, 00
0,1,2: 00, 01, 02, 10, 11, 12, 20, 21, 22, 00, 01, 10, 11, .. , 2.
, , .
for(maxdigit=0; maxdigit<10; ++maxdigit) {
for(digit1 = 0; digit1 <= maxdigit; ++digit1) {
for(digit2 = 0; digit2 <= maxdigit; ++digit2) {
for(digit3 = 0; digit3 <= maxdigit; ++digit3) {
for(digit4 = 0; digit4 <= maxdigit; ++digit4) {
if( digit1 < maxdigit && digit2 < maxdigit
&& digit3 < maxdigit && digit4 < maxdigit) continue;
print( digit1, digit2, digit3, digit4);
}}}}
}
, ,
00 | 01 | 02 | 03 | 04
----- | | |
10 11 | 12 | 13 | 14
---------- | |
20 21 22 | 23 | 24
--------------- |
30 31 32 33 | 34
--------------------
40 41 42 43 44
, "". , 4 = 2 ^ 2 , , 9 = 3 ^ 2 ..
, . 1 ^ 2 = 1, 2 ^ 2-1 ^ 2 = 3, 3 ^ 2-2 ^ 2 = 5, 4 ^ 2-3 ^ 2 = 7.
. 1 ^ 3 = 1, 2 ^ 3-1 ^ 3 = 9-1 = 8, 3 ^ 3-2 ^ 3 = 27-9 = 18 ..
.
, . , . , , .
, 3- x, y, z . k- , x = k, y = k, z = k. , x
for(shell=0;shell<=9;++shell) {
for(x=0;x<shell;++x) {
for(y=0;y<shell;++y)
print(x,y,shell);
for(z=0;z<=shell;++z)
print(x,shell,z);
}
for(y=0;y<=shell;++y)
for(z=0;z<=shell;++z)
print(shell,y,z);
}
d-. x1, x2,..., xd. k- (d-1) - x1 = k, x2 = k,..., xd = k. x1 = 0, x1 = k-1, x1 = 0 , d-1, .
function solve(int shell,int dim,String prefix) {
if(dim==1) {
print(prefix+shell);
return;
}
for(int x=0;x<shell;++x) {
String prefix2 = prefix + x;
solve(shell,dim-1,prefix2);
}
String prefix2 = prefix + shell;
hypercube(shell,dim-1,prefix2);
}
function hypercube(int shell,int dim,String prefix) {
if(dim==1) {
for(int x=0;x<=shell;++x)
println(prefix+x);
}
else {
for(int x=0;x<=shell;++x) {
String prefix2 = prefix + x;
hypercube(shell,dim-1,prefix2);
}
}
}
for(shell=0;shell<=9;++shell) {
solve(shell,4,"");
}