Nov-20-2019, 10:18 PM
My assignment is to create a class called "Squares", whose __init__(self, n) creates a table of 2**n by 2**n filled with zeros, and a function "turn(str)" which takes a string of a numbers. The digits of the number are by order the position of which quarter of the square gets turned from zero to one and vice versa, assuming 1 is upper left, 2 is upper right, 3 is lower left and 4 is lower right. So if my input is d=Suares(2), it would initialize an 4 by 4 table. d.turn('1') would turn all the numbers in the upper left quarter to their binary opposites. So d would look like this
[1, 1, 0, 0]
[1, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
However starting from a blank table of zeros d.turn('12') would turn numbers in the second quarter of the first quarter. So d would look like this
[0, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
I was thinking of splitting the string into a list and then slowly working into it using some elifs but don't know where to start. Any help is appreciated.
[1, 1, 0, 0]
[1, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
However starting from a blank table of zeros d.turn('12') would turn numbers in the second quarter of the first quarter. So d would look like this
[0, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
I was thinking of splitting the string into a list and then slowly working into it using some elifs but don't know where to start. Any help is appreciated.