Skip to content

Instantly share code, notes, and snippets.

@IevaZarina
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IevaZarina/e48f71d096a59a903a42 to your computer and use it in GitHub Desktop.
Save IevaZarina/e48f71d096a59a903a42 to your computer and use it in GitHub Desktop.
Xmas Gift Exchange
# -*- 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