generated from mwc/lab_dice
I wrote 2 new functions.
I could use classes to stimulate a deck of cards.
This commit is contained in:
@@ -18,10 +18,24 @@ class FiveDice:
|
|||||||
if face != 1:
|
if face != 1:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
def is_three_of_a_kind(self):
|
||||||
|
faces = self.faces()
|
||||||
|
for face in faces:
|
||||||
|
count = faces.count(face)
|
||||||
|
if count >= 3:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
dice = FiveDice()
|
def is_four_of_a_kind(self):
|
||||||
|
faces = self.faces()
|
||||||
|
for face in faces:
|
||||||
|
count = faces.count(face)
|
||||||
|
if count >= 4:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
successes = 0
|
successes = 0
|
||||||
trials = 1000000
|
trials = 1000000
|
||||||
|
dice= FiveDice()
|
||||||
for trial in tqdm(range(trials)):
|
for trial in tqdm(range(trials)):
|
||||||
dice.roll()
|
dice.roll()
|
||||||
if dice.all_ones():
|
if dice.all_ones():
|
||||||
|
|||||||
Reference in New Issue
Block a user