Skip to content

Instantly share code, notes, and snippets.

@yabberyabber
Last active March 12, 2018 03:11
Show Gist options
  • Save yabberyabber/fd454e9c5dfe69afe50c5db38b86574b to your computer and use it in GitHub Desktop.
Save yabberyabber/fd454e9c5dfe69afe50c5db38b86574b to your computer and use it in GitHub Desktop.
# These are the people who are invited to my wedding
GUESTS = [
"Linda",
"Paige",
"Lauren",
"Melissa",
"Ragnor",
"Thor",
"Gertrude",
"Yoshi",
"Mario",
"Upside-down Mario",
"Bradly",
"Oliver",
"Penelopy",
"Anne",
"Toshi",
"Jordon",
"Omar",
"Andrew",
"Jake",
"Jeremy",
"Adam",
"CJ",
"Michelle",
"Toby",
"Elephant",
"Pudding",
"Praying Mantis",
"Ghost"
"Aardvark",
"Chair",
]
# These are the people who can't sit at the same table with each other
CONFLICTS = [
("Ghost", "Elephant"), # If the Elephant gets spooked, we're all trampled!
("Bradly", "Yoshi"), # Yoshi has trouble keeping his tongue to himself (if you know what I mean)
("Chair", "Toby"), # Toby is a strict squatafarian - Doesn't believe in chairs
("Anne", "Jordon"), # Anne and Jordon used to date until Anne made fun of Jordon's name being misspelled
("Michelle", "CJ"), # Michelle doesn't like CJ because CJ sounds like DJ and DJ died in a boating accident
("Pudding", "Praying Mantis"), # Praying Manti can't swim
("Aardvark", "Andrew"), # Andrew is jealous that Aardvark comes first alphabetically
("Penelopy", "Oliver"), # They just don't like each other...
("Bradly", "Mario"), # Bradly's kids keep playing paper mario with the volume full blast and if Bradly hears that fucker one more time he's gonna snap
("Thor", "Gertrude"), # Thor has a drinking problem and Gertrude is an enabler
("Upside-down Mario", "Mario"), #Upside-down Mario doesn't like how Mario isn't upside down
("Adam", "CJ"), # beep beep boop boop
("Toby", "Omar"), # Omar is allergic to dogs and Toby is a dog
("Lauren", "Andrew"), # I don't want to see that girl again
("Lauren", "Jake"), # Neither do you
("Lauren", "Melissa"), # We don't want to enable them
("Linda", "Andrew"), # She's my friends mom and she keeps commenting on my fb posts weird stuff o:
("Ragnor", "Pudding"), # Ragnor prefers his calories in alcohol form
("Elephant", "Praying Mantis"), # Elephant might step on mantis :(
("Upside-down Mario", "CJ"), # CJ is actually a big fan of the classic rightside-up Mario
("Mario", "CJ"), # Wait I was wrong about that last point...
]
# You can us as many tables as you like and each table can have as many
# guests as you like
example_assignment = {
0: ["Linda", "Paige", "Lauren"],
1: ["Elephant"],
}
def validate(seating_chart, conflicts, guests):
"""
Given a seating chart, check that all the people are seated and that no
table has two conflicting people.
"""
people_seated = []
for table in seating_chart.values():
for person in table:
if person is None:
continue
if person in people_seated:
raise Exception("{0} Was seated twice!".format(person))
if person not in guests:
raise Exception("{0} Is not a guest!".format(person))
people_seated.append(person)
for guest in guests:
if guest not in people_seated:
raise Exception("{0} Doesn't have a seat!".format(guest))
for table in seating_chart.values():
for personA, personB in conflicts:
if personA in table and personB in table:
raise Exception("{0} and {1} Seated at the same table!".format(
personA, personB))
def can_sit_together(personA, personB, conflicts):
"Can personA sit with personB? Check the conflicts map"
return not ((personA, personB) in conflicts or
(personB, personA) in conflicts)
def main(conflicts, guests):
# Write your algorithm here!
return {}
if __name__ == '__main__':
seating_chart = main(CONFLICTS, GUESTS)
import pprint
pp = pprint.PrettyPrinter()
pp.pprint(seating_chart)
validate(seating_chart, CONFLICTS, GUESTS)
print("Valid mapping")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment