A Pythonian Look at the Family Tree Conundrum

vegaseat 0 Tallied Votes 194 Views Share

The other day I was looking at my family tree. There are my parents Antonio and Lucy Vegaseat, then my grandparents Alfonso and Ludmilla Vegaseat on my father's side and Roland and Helga Gruenspan on my mother's side. Then come my great grandparents, by now there are eight of those. It was time for a small Python program to figure out how many great great great ... grandparents I had.

# The family tree conundrum ...
# you have two parents, your parents each have two parents, that makes it
# four grandparents for you, then there must be eight great grandparents
# and so on.  A light hearted look at a serious problem.
# tested with Python24    vegaseat      24jul2005

generations = 3
number_of_parents = 2 ** generations
print "after 3 generation we have %d great grandparents" % number_of_parents

print

# going back 40 generations
for generations in range(4, 41):
    number_of_parents = 2 ** generations
    print "In %d generation we have %d (g)parents" % (generations, number_of_parents)

print
    
print """Going back in your family tree for 40 generations, or around a thousand years,
there should be over one trillion great-great-great-...-grandparents you could 
lay claim to being related with.

Hmmm, that alone is more people then ever lived!  We demand an explanation from 
our government!"""
bumsfeld 413 Nearly a Posting Virtuoso

I do not know Python much, but I was taught that you start with Adam and Eve, not one trillion old people!

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Wouldn't that be a lot of incest?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.