Commit a70eded4 authored by Sanchit's avatar Sanchit

Final solutions of all parts of q1

parent ab9db2ae
......@@ -86,7 +86,52 @@ def incendio(my_integer):
# 'm': integer that divides n
# return type: int numpy Ndarray; dim: nxn
def alohomora(n, m):
pass
checkerboard = np.zeros((n,n), dtype=int)
turn,count,row_turn,row_count = (0,0,0,0)
for row in range(len(checkerboard)):
if row_turn == 0 and row_count < m:
for col in range(len(checkerboard[0])):
if (turn == 0 and count < m):
checkerboard[row][col] = 1
count += 1
if (count >= m):
turn = 1
count = 0
elif (turn == 1 and count <= m):
count += 1
if (count + 1 > m):
turn = 0
count = 0
turn = 0
row_count += 1
if (row_count >= m):
row_turn = 1
row_count = 0
turn = 1
continue
if row_turn == 1 and row_count < m:
for col in range(len(checkerboard[0])):
if (turn == 0 and count < m):
checkerboard[row][col] = 1
count += 1
if (count >= m):
turn = 1
count = 0
elif (turn == 1 and count <= m):
count += 1
if (count + 1 > m):
turn = 0
count = 0
turn = 1
row_count += 1
if (row_count >= m):
row_turn = 0
row_count = 0
turn = 0
continue
return checkerboard
# ---- Task (d) -------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment