Created
October 11, 2013 03:11
-
-
Save jsomers/6929017 to your computer and use it in GitHub Desktop.
A better method of generating Yahtzee-ish dice possibilities in Python
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
from itertools import product | |
def iterate_dice_simple(diceNums, diceToHold): | |
roles = list(product(range(1, 7), repeat=len(diceNums))) | |
return [r for r in roles if has_held_dice(r, diceNums, diceToHold)] | |
def has_held_dice(r, diceNums, diceToHold): | |
for i in range(len(diceToHold)): | |
if diceToHold[i] == 0: continue | |
if r[i] != diceNums[i]: return False | |
return True | |
print iterate_dice_simple([3, 5, 4], [0, 1, 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment