Triangle as Binary Array
Start Timer
0:00:00
Given an (integer) height h
and base b
, write a function draw_isosceles_triangle
that returns the shape of the isosceles triangle using (a 2D list) of 0
s and 1
s, where 0
and 1
represent the space outside and inside of the triangle, respectively.
If the given height h
and base b
cannot make a triangle, return None
.
Note: Valid arguments for b
should be odd
Example 1
Input:
h = 2
b = 3
Output:
draw_isosceles_triangle(h,b) -> [
[0,1,0],
[1,1,1]
]
Example 2
Input:
h = 3
b = 9
Output:
draw_isosceles_triangle(h,b) -> [
[0,0,0,0,1,0,0,0,0],
[0,0,1,1,1,1,1,0,0],
[1,1,1,1,1,1,1,1,1]
]
Example 3
Input:
h = 5
b = 9
Output:
draw_isosceles_triangle(h,b) -> [
[0,0,0,0,1,0,0,0,0],
[0,0,0,1,1,1,0,0,0],
[0,0,1,1,1,1,1,0,0],
[0,1,1,1,1,1,1,1,0],
[1,1,1,1,1,1,1,1,1]
]
Example 4
Input:
h = 9
b = 9
Output:
draw_isosceles_triangle(h,b) -> None
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments