Created
February 8, 2021 16:18
-
-
Save VictorWesterlund/6e82890e11b40bb1c3c63aaedc421b70 to your computer and use it in GitHub Desktop.
Python Craps
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
# https://colab.research.google.com/drive/1TOeASp1DeDlkNxEqpgnK3Rf8_q495GD9?usp=sharing | |
# Craps is a dice game usually found at casinos. This python script tries to generate | |
# the largest possible sequence of psudo-random dice rolls before "sevening out". | |
# The world record is currently held by Patricia Demauro, with a score of 154. | |
import random | |
from functools import reduce | |
longest = 0 | |
failed = 0 | |
sequence = [] | |
def roll(): | |
return random.randint(1,6) | |
def craps(rolls = 0): | |
global longest | |
global failed | |
global sequence | |
rolls = rolls + 1 | |
dice = [roll(),roll()] | |
sequence.append(dice) | |
if(reduce(lambda x, y: x+y, dice) == 7): | |
if(rolls > longest): | |
longest = rolls | |
print(f"{rolls} rolls, that's a new record! It only took us {failed} craps to get there.") | |
with open("sequence.txt", "w") as f: | |
f.write(str(sequence)) | |
f.close() | |
failed = -1 | |
failed = failed + 1 | |
sequence = [] | |
return rolls | |
craps(rolls) |
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
9 rolls, that's a new record! It only took us 0 craps to get there. | |
10 rolls, that's a new record! It only took us 0 craps to get there. | |
13 rolls, that's a new record! It only took us 4 craps to get there. | |
19 rolls, that's a new record! It only took us 22 craps to get there. | |
36 rolls, that's a new record! It only took us 15 craps to get there. | |
39 rolls, that's a new record! It only took us 356 craps to get there. | |
57 rolls, that's a new record! It only took us 2625 craps to get there. | |
61 rolls, that's a new record! It only took us 29688 craps to get there. | |
65 rolls, that's a new record! It only took us 5756 craps to get there. | |
69 rolls, that's a new record! It only took us 17297 craps to get there. | |
84 rolls, that's a new record! It only took us 3335 craps to get there. | |
90 rolls, that's a new record! It only took us 3880145 craps to get there. | |
93 rolls, that's a new record! It only took us 6478640 craps to get there. | |
94 rolls, that's a new record! It only took us 6279793 craps to get there. | |
100 rolls, that's a new record! It only took us 14157124 craps to get there. | |
102 rolls, that's a new record! It only took us 21401819 craps to get there. | |
103 rolls, that's a new record! It only took us 150779093 craps to get there. | |
111 rolls, that's a new record! It only took us 107975452 craps to get there. |
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
[[1, 5], [1, 5], [2, 2], [5, 3], [2, 4], [5, 6], [3, 6], [1, 1], [1, 4], [1, 3], [6, 6], [6, 6], [6, 2], [6, 2], [1, 2], [6, 6], [2, 4], [1, 5], [1, 3], [1, 5], [5, 1], [2, 3], [1, 3], [1, 5], [3, 3], [4, 4], [5, 1], [3, 3], [5, 6], [1, 3], [3, 6], [5, 5], [4, 4], [5, 5], [6, 5], [4, 5], [6, 5], [4, 2], [5, 3], [3, 1], [3, 5], [1, 5], [2, 4], [3, 2], [6, 2], [2, 2], [6, 2], [6, 4], [3, 2], [2, 6], [2, 4], [3, 2], [1, 1], [1, 5], [5, 3], [4, 2], [6, 6], [1, 1], [2, 1], [6, 3], [4, 6], [2, 3], [2, 6], [5, 4], [3, 6], [5, 6], [4, 6], [5, 4], [4, 1], [4, 5], [2, 3], [5, 4], [2, 6], [2, 3], [1, 1], [4, 4], [4, 1], [1, 5], [1, 2], [6, 5], [5, 1], [3, 5], [2, 3], [2, 1], [1, 5], [3, 2], [5, 5], [3, 3], [1, 3], [1, 4], [5, 6], [6, 3], [4, 1], [3, 1], [4, 4], [5, 5], [2, 1], [4, 2], [4, 5], [4, 2], [6, 5], [4, 2], [6, 3], [2, 4], [3, 2], [3, 1], [5, 3], [4, 4], [6, 5], [3, 2], [6, 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment