Skip to content

Instantly share code, notes, and snippets.

@drvinceknight
Created December 1, 2016 14:40
Show Gist options
  • Save drvinceknight/76f87af145ab1a6c8c2e37ccaacaaf37 to your computer and use it in GitHub Desktop.
Save drvinceknight/76f87af145ab1a6c8c2e37ccaacaaf37 to your computer and use it in GitHub Desktop.
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()
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