import random
# 14.7106 rolls to get all 6 numbers with fair dice
# 25.221 rolls to get all 6 numbers with unfair dice
def fairdice():
trials = int(input("Enter number of trials: "))
total = 0
for i in range(trials):
total += fairroll()
avg = total / trials
print(avg)
def fairroll():
rolls = 0
one = False
two = False
three = False
four = False
five = False
six = False
while True:
if one == True and two == True and three == True and four == True and five == True and six == True:
return rolls
break
else:
var = random.randint(1, 6)
rolls += 1
if var == 1:
one = True
elif var == 2:
two = True
elif var == 3:
three = True
elif var == 4:
four = True
elif var == 5:
five = True
elif var == 6:
six = True
else:
None
def unfairdice():
trials = int(input("Enter number of trials: "))
total = 0
for i in range(trials):
total += unfairroll()
avg = total / trials
print(avg)
def unfairroll():
rolls = 0
one = False
two = False
three = False
four = False
five = False
six = False
while True:
if one == True and two == True and three == True and four == True and five == True and six == True:
return rolls
break
else:
var = random.random()
rolls += 1
if var <= .30 and var >= 0:
one = True
elif var <= .55 and var > .30:
two = True
elif var <= .70 and var > .55:
three = True
elif var <= .85 and var > .70:
four = True
elif var <= .95 and var > .85:
five = True
elif var < 1 and var > .95:
six = True
else:
None
dfa = {0:{'0':0, '1':1},
1:{'0':2, '1':0},
2:{'0':1, '1':2}}
def accepts(s):
state = 0
for c in s:
state = dfa[state][c]
return state in {0}
# 10010110101001010110100101011010 - Accepted
# 1001011010100101010101010101010100010100101010010010100101011010 - Rejected
def calc():
fcn = str(input("Enter a function in terms of x: "))
a = int(input("Enter A: "))
b = int(input("Enter B: "))
n = 100
dx = (b - a)/n
result = 0.5*fcn(a) + sum([fcn(a + i*dx) for i in range(1, n)]) + 0.5*f(b)
result *= dx
return result