-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckNumDiceRollsThatCanGetTarget.py
More file actions
45 lines (44 loc) · 1.31 KB
/
CheckNumDiceRollsThatCanGetTarget.py
File metadata and controls
45 lines (44 loc) · 1.31 KB
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
43
44
45
class Solution:
def numRollsToTarget(self, d: int, f: int, target: int) -> int:
a = []
numRollCount = 0
for i in range(1, d+1):
for j in range(1,f+1):
if j == 1:
b = []
b.append(j)
a.append(b)
initial1 = a[0]
initial2 = a[1]
first = True
n = True
k = 2
while(n):
if not first:
if k >= d:
n = False
continue
else:
initial1 = val
initial2 = a[k]
k += 1
val = []
for i in range(0, len(initial1)):
for j in range(0, len(initial2)):
if first:
val1 = [initial1[i], initial2[j]]
val.append(val1)
else:
val1 = initial1[i] + list(map(int, str(initial2[j])))
val.append(val1)
if first:
first = False
for i in val:
if sum(i) == target:
numRollCount += 1
return numRollCount
d = 2
f = 6
target = 7
s = Solution()
print(s.numRollsToTarget(d,f,target))