Last active
August 29, 2015 14:10
-
-
Save IevaZarina/e48f71d096a59a903a42 to your computer and use it in GitHub Desktop.
Xmas Gift Exchange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import random | |
def getRandomPerson(ppl): | |
return ppl[random.randint(0,len(ppl)-1)] | |
def good_pair(ignore_ppl, chosen1, chosen2): | |
for pair in ignore_ppl: | |
if chosen1 in pair and chosen2 in pair: | |
return False | |
return True | |
ppl = ['x', 'y', 'z', 'a', 'b', 'c'] | |
ignore_ppl = [['x', 'y'],['x', 'c']] | |
#Ja lasa failu no stdin | |
#ppl = [line.strip() for line in open(str(sys.argv[1]))] | |
#ignore_ppl = [line.split() for line in open(str(sys.argv[2]))] | |
result = [] | |
while len(ppl) > 0: | |
chosen = getRandomPerson(ppl) | |
while result and not good_pair(ignore_ppl, chosen, result[len(result) - 1]): | |
chosen = getRandomPerson(ppl) | |
result.append(chosen) | |
ppl.remove(chosen) | |
for i in range(0, len(result)): | |
if i is len(result) - 1: | |
print(result[i] + " dāvina dāvanu " + result[0]) | |
else: | |
print(result[i] + " dāvina dāvanu " + result[i+1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment