Skip to content

Instantly share code, notes, and snippets.

@michaeldfallen
Created July 15, 2013 22:13
Show Gist options
  • Save michaeldfallen/6003987 to your computer and use it in GitHub Desktop.
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…
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
@crobird
Copy link

crobird commented Jul 15, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment