Solution to problem on Slide 4:
Convert the integer into binary, make the string 32 characters long, replace spaces with zeros, and convert it back into an integer.
n = bin(n)[2:]
n = '%32s' % n
n = n.replace(' ','0')
return int(n[::-1],2)
Solution to problem on Slide 5:
Basically, maintain an array and iterate through it with the conditions.
orig = [[0 for i in range(4)] for j in range(4)]
#too lazy to implement the pad-with-zero condition, pretty self explainatory in my opinion
for i in range(4):
for j in range(4):
orig[i][j] = input()
for i in range(5):
val = orig
x,y = input(),input()
x-=1;y-=1
for j in range(6):
dir = val[y][x]
val[y][x]+=1
if dir==0:
x+=1
if dir==1:
x-=1
if dir==2:
y-=1
if dir==3:
y+=1
y = (y +4)%4
x = (x +4)%4
print(x,y)