Created
April 26, 2012 04:16
-
-
Save chrisc24/2495763 to your computer and use it in GitHub Desktop.
Snakes and ladders!
This file contains 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
teleports = {1:38, 4:14, 9:31, 16:6, 21:42, 36:44, 47:26, 49:11, 51:67, 56:53, 62:19, 64:60, 71:91, 80:100, 87:24, 93:73, 95:75, 98:78} | |
board = [[] for i in range(101)] | |
def getPossibleNextSquares(x): | |
nextSquares = [] | |
for i in range(1, 7): | |
if x + i in teleports.keys(): | |
nextSquares.append(teleports[x+i]) | |
elif x + i >= 101: | |
nextSquares.append(x) | |
else: | |
nextSquares.append(x+i) | |
return nextSquares | |
def updateSquareForRound(square, numRound, addValue): | |
board[square][numRound] = board[square][numRound] + addValue | |
def appendZeroToAll(): | |
for valueList in board: | |
valueList.append(0) | |
appendZeroToAll() | |
board[0][0] = 1 | |
for numRound in range(1, 41): | |
appendZeroToAll() | |
for index in range(101): | |
if board[index][numRound-1] != 0: | |
nextSquares = getPossibleNextSquares(index) | |
for nextSquare in nextSquares: | |
updateSquareForRound(nextSquare, numRound, board[index][numRound-1]) | |
def boardPercentage(): | |
numRounds = len(board[0]) | |
for currentRound in range(numRounds): | |
print("ROUND", currentRound) | |
for index in range(len(board)): | |
if board[index][currentRound] != 0: | |
print(index, ":", (1.0*board[index][currentRound]/(6 ** currentRound)*100)) | |
boardPercentage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment