Created
November 17, 2018 04:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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