aboutsummaryrefslogtreecommitdiff
path: root/challenge-247/eric-cheung/python/ch-1.py
blob: d613fb49ddee3f3496a6028114b0f20ec46c9fc6 (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
29
30
31
from random import randint

## Example 1
arrNames = ["Mr. Wall", "Mrs. Wall", "Mr. Anwar", "Mrs. Anwar", "Mr. Conway", "Mr. Cross"]
nMaxShareFamilyGift = 0

## Example 2
## arrNames = ["Mr. Wall", "Mrs. Wall", "Mr. Anwar"]
## nMaxShareFamilyGift = 1

arrGiftFrom = [-1] * len(arrNames)  ## List storing the index storing who the gift is sent

for nIndxLoop, strNameLoop in enumerate(arrNames):

    if nMaxShareFamilyGift == 0:
        arrAvailList = [nIndx for nIndx, strLoop in enumerate(arrNames) if strLoop != strNameLoop and strLoop.split(" ")[-1] != strNameLoop.split(" ")[-1] and arrGiftFrom[nIndx] == -1]
    else:
        arrAvailList = [nIndx for nIndx, strLoop in enumerate(arrNames) if strLoop != strNameLoop and strLoop.split(" ")[-1] == strNameLoop.split(" ")[-1] and arrGiftFrom[nIndx] == -1]

        nMaxShareFamilyGift = nMaxShareFamilyGift - 1

    nGiftTo = arrAvailList[randint(0, len(arrAvailList) - 1)]
    arrGiftFrom[nGiftTo] = nIndxLoop

    print (strNameLoop + " --> " + arrNames[nGiftTo])

    print ("")

print ("From : " + " | ".join(arrNames))
print ("To : " + " | ".join([strNameLoop for nIndxLoop, strNameLoop in sorted(zip(arrGiftFrom, arrNames))]))