Skip to content

Instantly share code, notes, and snippets.

@yabberyabber
Created December 30, 2019 23:02
Show Gist options
  • Save yabberyabber/655f15d8f126ab3d8f2627ac55aaddb7 to your computer and use it in GitHub Desktop.
Save yabberyabber/655f15d8f126ab3d8f2627ac55aaddb7 to your computer and use it in GitHub Desktop.
class Person( object ):
def __init__( self, name, parent ):
self.name = name
self.children = []
self.parent = parent
if parent:
parent.children.append( self )
banana = Person( "Banana" )
cherry = Person( "Cherry", parent=banana )
apple = Person( "Apple", parent=banana )
zooboomafoo = Person( "Zebra", parent=apple )
def is_sibling( x, y ):
"""Returns true if x and y are direct siblings"""
raise NotImplementedException()
assert is_subling( cherry, apple )
assert not is_sibling( cherry, banana )
def is_parent( x, y ):
"""Returns true if x is the parent of y"""
raise NotImplementedException()
assert is_parent( banana, cherry )
assert not is_aprent( cherry, banana )
def is_first_cousin( x, y ):
"""Returns true if x and y are first cousins"""
raise NotImplementedException()
def is_second_cousin( x, y ):
"""Returns true if x and y are second cousins"""
raise NotImplementedException()
def is_cousin( x, y, degree=1 ):
"""Returns true if x and y are cousings to the |degree| degree"""
raise NotImplementedException()
def is_grandparent( x, y, greatness=0 ):
"""If greatness is 0, check whether x is the grandparent of y.
If greatness is 1, check whether x is the great grandparent of y.
If greatness is 2, check whether x is the great great grandparent of y.
etc."""
raise NotImplementedException()
def is_niece( x, y, greatness=0 ):
"""Check whether x is the (great?) niece of y. Your niece is your sibling's
daughter. Your great niece is your sibling's grand-daughter. etc."""
raise NotImplementedException()
def find_relation( x, y ):
"""Return a string representation of the relation between x and y. Is
x the parent of y? the niece of y? the grandmother of y? etc."""
raise NotImplementedException()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment