Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Kroppeb
Forked from ashtonmv/ancient_knights_code.py
Last active November 15, 2018 13:03
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 Kroppeb/1c91e05b9f85880f0372c42c425930cc to your computer and use it in GitHub Desktop.
Save Kroppeb/1c91e05b9f85880f0372c42c425930cc to your computer and use it in GitHub Desktop.
The Ancient Knights Code
class Knight:
def __init__(self, name):
self.name = name
self.l = len(name)
self.honor = 0
def quest1(self):
if self.l > 6:
self.honor += 1
def quest2(self):
if not (self.l - self.honor % 2):
self.honor += 1
def quest3(self):
if self.name != "Lancelot": # aka not a cheating mouthbreather
self.honor += 1
else:
self.honor -= 1
def quest4(self):
if len(set(self.name)) == self.l:
self.honor+= 1
quests = [quest1, quest2, quest3, quest4]
round_table = [ "Lancelot", "Gawain", "Geraint",
"Percival", "Gareth", "Belivere", "Galahad"]
knights = []
for name in round_table:
knight = Knight(name)
for quest in knight.quests:
quest(knight)
knights.append(knight)
knights.sort(key=lambda x: x.honor, reverse=True)
best_knight = knights[0]
print(best_knight.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment