aboutsummaryrefslogtreecommitdiff
path: root/challenge-234/eric-cheung/python/ch-2.py
blob: 356ebee5c47b6e1456114ee166df4e7b60a35cb8 (plain)
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
import sys
from itertools import combinations
import numpy as np

nListCount = 3

arrInput = [4, 4, 2, 4, 3]  ## Example 1
## arrInput = [1, 1, 1, 1, 1]  ## Example 2
## arrInput = [4, 7, 1, 10, 7, 4, 1, 1]  ## Example 3

arrUniq = list(set(arrInput))

## print (arrUniq)

if len(arrUniq) < nListCount:
    print (0)
    sys.exit()

nNumCount = 0

arrCombList = combinations(arrUniq, nListCount)

for arrCombLoop in list(arrCombList):
    nProduct = np.prod([arrInput.count(arrCombLoop[nLoop]) for nLoop in range(nListCount)])
    nNumCount = nNumCount + nProduct

print (nNumCount)