(The text asks how many boxes there are in the picture)
Now you are required to generate such a problem and its answer.
Input
- an integer
n
- (optionally) random source of two values, in case you don't want to use the default random.
Output can be
a 3D array
A[n][n][n]
of booleans, whereA[i][j][k] => (i==0 || A[i-1][j][k]) && (j==0 || A[i][j-1][k]) && (k==0 || A[i][j][k-1])
(assuming 0-index)
where&&
is logical AND,||
is logical OR, and=>
is "implies" (ifX
is true, thenY
is true).Basically this says that if you have a box at some position then for each coordinate that coordinate must be either
0
or also have a box if that coordinate is one less. So no holes in any direction that gets you closer to the origin.a 2D array
B[n][n]
of integers, whereB[i][j]
means how manyk
satisfyA[i][j][k]
Basically this is the height of the stacks where these heights can't become lower in any direction that gets you closer to the origin.
Besides the array, the amount of boxes (how many
i,j,k
satisfyA[i][j][k]
)
Every valid output should have nonzero probability to be outputted.
Example: (Here use 2D output format for convenience)
1 => [[0]] 0 or [[1]] 1
2 => [[0,0],[0,0]] 0
[[1,0],[0,0]] 1
[[1,0],[1,0]] 2
[[1,1],[0,0]] 2
[[1,1],[1,0]] 3
[[1,1],[1,1]] 4
[[2,0],[0,0]] 2
[[2,0],[1,0]] 3
[[2,0],[2,0]] 4
[[2,1],[0,0]] 3
[[2,1],[1,0]] 4
[[2,1],[1,1]] 5
[[2,1],[2,0]] 5
[[2,1],[2,1]] 6
[[2,2],[0,0]] 4
[[2,2],[1,0]] 5
[[2,2],[1,1]] 6
[[2,2],[2,0]] 6
[[2,2],[2,1]] 7 or
[[2,2],[2,2]] 8
So for input 2
your program should randomly return one of the 20 possible outputs, and if run enough times every one of them should be returned at some point.
Your program must terminate.
Winning criteria
This is code-golf, shortest code in bytes win!
std::collections::BinaryHeap::new<Box<i32>>()
(generates a heap of boxes) \$\endgroup\$