Created
November 18, 2018 18:02
-
-
Save manvillej/457a934790484ae9bc893cb2d866f0d0 to your computer and use it in GitHub Desktop.
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 getPossibilities(startingPosition, turns): | |
""" | |
calculates the total number of uniques paths from the starting position in N turns for the transition matrix | |
""" | |
# edge case: if turns is 0, total number of unique paths is 1 | |
if turns == 0: | |
return 1 | |
# edge case: if starting position is 5 and turns is not 0, total number of unique paths is always 0 | |
if startingPosition == 5: | |
return 0 | |
# map original positions to new positions | |
mappedStartingPosition = getMappedStartingPosition(startingPosition) | |
# our transition matrix | |
transitionMatrix = np.matrix([ | |
[0, 1, 1, 0], | |
[2, 0, 0, 0], | |
[2, 0, 0, 1], | |
[0, 0, 2, 0]], dtype=object) | |
# get our new matrix N turns ahead | |
newMatrix = np.linalg.matrix_power(transitionMatrix, turns) | |
# sum the relevant row | |
return np.sum(newMatrix[mappedStartingPosition]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment