Created
December 1, 2016 14:40
-
-
Save drvinceknight/76f87af145ab1a6c8c2e37ccaacaaf37 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
import collections | |
import random | |
def dice_roll(): | |
return random.randint(1, 6) | |
def index_of_same(rolls): | |
counter = collections.Counter(rolls) | |
rolls.sort(key= lambda x:(counter[x], x)) | |
nbr_the_same = max(counter.values()) | |
return range(len(rolls) - nbr_the_same) | |
def reroll(rolls): | |
reroll_indices = index_of_same(rolls) | |
for index in reroll_indices: | |
rolls[index] = dice_roll() |
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
random.seed(2) | |
rolls = [1, 1, 4, 3, 2] | |
count = 1 | |
while max(rolls) != min(rolls): | |
reroll(rolls) | |
count += 1 | |
print(rolls) | |
count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment