Given guaranteed strictly positive integers \$w\$ and \$n\$, output
- An equilateral triangle array with side length \$w\$, filled with two distinct, consistent values. I'll call these
0
and1
but they do not have to be equal to0
and1
. - The number of
1
s inside this array must be equal to \$n\$. - The output triangle must be symmetrical, meaning that it is the same when flipped horizontally or diagonally (your choice).
- An equilateral triangle array can be an array with \$w\$ elements where for \$1\$ to \$w\$ (inclusive), there is a sub-array with that number of elements inside of \$w\$ (for example, but it may be outputted via ascii-art, see below).
(\$n\$ values are guaranteed to fit in the triangle)
Examples
w=3, n=1
1
0 0
0 0 0
w=3, n=2
0
1 1
0 0 0
w=3, n=3
1
1 1
0 0 0
w=3, n=4
0
1 1
1 0 1
w=3, n=5
0
1 1
1 1 1
w=3, n=6
1
1 1
1 1 1
Valid Output Format List
In this case the distinct values are 1
and 0
.
Possible output triangles (all considered equivalent) with 1
s at their corners and center and a width of 4 are:
1
0 0
0 1 0
1 0 0 1
1
00
010
1001
[[1],[0,0],[0,1,0],[1,0,0,1]]
1 0 0 1
0 1 0
0 0
1
[[1],[0,0],[0,1,0],[1,0,0,1]]
1
0
00
11
00
0
1
1
0
0 0
1 1
0 0
0
1
here is a test case validator in Jq, takes {"w": w, "n": n, "a": result you wish to check}
(in the JSON array format like [[1],[0,0],[0,1,0],[1,0,0,1]]
)