Created
July 15, 2013 22:13
-
-
Save michaeldfallen/6003987 to your computer and use it in GitHub Desktop.
Some pseudo-code for CGPGrey. Assumes monarch is an object that has methods: - hasChildren - hasSons OR hasDaughters - hasSons - returns true if they have at least one son - hasDaughters - returns true if they have at least one daughter - sons object with eldest method that returns oldest son - daughters object with eldest method that returns ol…
This file contains 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
def MalePrimoGenetor(monarch): | |
if monarch.hasChildren is False: | |
return MalePrimoGenetor(monarch.parent) | |
else | |
if monarch.hasSons is True: | |
return monarch.sons.eldest | |
else if monarch.hasDaughters is True: | |
return monarch.daughters.eldest | |
else | |
return none |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since you’re returning on each conditional, you could choose to clean up the code, by dropping the unneeded conditionals, like this:
def MalePrimoGenetor(monarch):
if monarch.hasChildren is False:
return MalePrimoGenetor(monarch.parent)
if monarch.hasSons is True:
return monarch.sons.eldest
if monarch.hasDaughters is True:
return monarch.daughters.eldest
return none
More simplified, but the intent might be more clear by leaving them in.