Skip to content

Instantly share code, notes, and snippets.

@scholtes
Created August 9, 2021 09:00
Show Gist options
  • Save scholtes/315639c059bb508f50dfd660a7f56924 to your computer and use it in GitHub Desktop.
Save scholtes/315639c059bb508f50dfd660a7f56924 to your computer and use it in GitHub Desktop.
farckle.py
def is_farcle(dice):
return not (
1 in dice
or 5 in dice
or has_3_of_kind(dice)
or has_1_thru_6(dice)
)
def has_3_of_kind(dice):
for i in [1,2,3,4,5,6]:
if dice.count(i) >=3:
return True
return False
def has_1_thru_6(dice):
return len(list(set(dice))) == 6
def get_all_dices_len_n(n):
if n == 1:
return [[1], [2], [3], [4], [5], [6]]
less_dices = get_all_dices_len_n(n-1)
dices = []
for i in [1,2,3,4,5,6]:
for less_dice in less_dices:
dices.append([i] + less_dice)
return dices
def get_farcle_count(dices):
count = 0
for dice in dices:
if is_farcle(dice):
count += 1
return count
def do_all_farcle_counts():
for i in [1,2,3,4,5,6]:
dices = get_all_dices_len_n(i) #always has len 6**i
farcles = get_farcle_count(dices)
prob = farcles / 6**i
print(f"For {i} dice probability of farcle is {farcles}/{6**i} --- ({100*prob}%)")
if __name__ == '__main__':
do_all_farcle_counts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment