3 of 4
address @pxeger's tag suggestion and @user's confusion https://chat.stackexchange.com/transcript/message/58053324#58053324

Symmetrical Triangles

Given a positive integer \$w\$ and a positive integer \$n\$, output

  • An equilateral triangle array with side length \$w\$, filled with two distinct, consistent values. I'll call these 0 and 1 but they do not have to be equal to 0 and 1.
  • The number of 1s inside this array must be equal to \$n\$.
  • The output triangle must be symmetrical, meaning that it is the same when flipped horizontally or vertically (your choice).

(The number of values in the triangle is guaranteed to be greater than or equal to \$n\$)

Valid Output Format List

In this case the distinct values are 1 and 0. Possible output triangles (all considered equivalent) with 1s 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

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

Meta Questions

  • Dupe?
  • More tags?
  • Should I allow/disallow more output formats?
  • Is "An equilateral triangle array" clear, or is there a way I can clarify it?
  • Especially relevant test cases?
  • Is there an easy way to take up less vertical space and still have a good amount of test cases?