Skip to content

Instantly share code, notes, and snippets.

@manvillej
Created November 17, 2018 04:57
Show Gist options
  • Save manvillej/b3ec17a7d8ade85331c6d999781409a1 to your computer and use it in GitHub Desktop.
Save manvillej/b3ec17a7d8ade85331c6d999781409a1 to your computer and use it in GitHub Desktop.
returns a matrix equal to the original matrix multiplied by itself a number of times equal to the number of turns minus one
def getMatrix(matrix, turns):
"""
returns a matrix equal to the original matrix multiplied by itself a number of times equal to the number of turns minus one
"""
if turns==1:
return matrix
else:
turnsBaseTwo = math.log(turns, 2)
if turnsBaseTwo.is_integer():
return getBaseTwoTurnsMatrix(matrix, int(turnsBaseTwo))
else:
remainder = turns - 2**int(turnsBaseTwo)
# casting turnsBaseTwo into int as float can cause an exception
largestBaseTwoMatrix = getBaseTwoTurnsMatrix(matrix, int(turnsBaseTwo))
remainderMatrix = getMatrix(matrix, remainder)
return largestBaseTwoMatrix*remainderMatrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment