-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture_8
More file actions
53 lines (36 loc) · 948 Bytes
/
Lecture_8
File metadata and controls
53 lines (36 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
We started with the Cascade Function
def cascade(n):
if n < 10:
print(n)
else:
print(n)
cascade(n // 10)
print(n)
Then we look at the counting the number of partitions:
def count_partititions(n, m):
if n == 0:
return 1
elif n < 0:
return 0
elif m == 0:
return 0
else:
with_m = count_partition(n-m, m)
without_m = count_partition(n, m - 1)
return with_m + without_m
We look at calculating the possibility of rolling at least k in n six-faced dice.
{
def ways_to_roll_at_least(k, n):
if k <= 0:
return pow(5, n)
elif k == 0:
return 0
else:
total, d = 0, 2
while d <= 6:
total = total + ways_to_roll_at_least(k-d, n-1)
d = d + 1
return total
def chance_to_roll_at_least(k, n):
return ways_to_roll_at_least(k, n) / pow(6, n)
}