/*
count_anc - a LifeLines ancestors counting program
	 by Jim Eggert (eggertj@atc.ll.mit.edu)
	 Version 1,  19 November 1992

This program counts ancestors of a person by generation.
Only unique individuals in each generation are counted.
A person counts in all the generations he/she is in,
but only counts once in the grand total.
*/

proc main ()
{
    getindimsg(person,"Enter person to count ancestors of")
    indiset(thisgen)
    indiset(allgen)
    addtoset(thisgen, person, 0)
    print("Counting generation ")
    "Number of ancestors of " key(person) " " name(person)
    " by generation:\n"
    set(thisgensize,1)
    set(gen,1)
    while(thisgensize) {
	set(thisgensize,0)
	forindiset(thisgen,person,val,thisgensize) { "" }
	if (thisgensize) {
	    set(gen,sub(gen,1))
	    print(d(gen)) print(" ")
	    "Generation " d(gen) " has " d(thisgensize) " individual"
	    if (gt(thisgensize,1)) { "s" }
	    ".\n"
	    set(thisgen,parentset(thisgen))
	    set(allgen,union(allgen,thisgen))
	}
    }
    forindiset(allgen,person,val,allgensize) { "" }
    "Total unique ancestors in generations " d(gen) " to -1 is "
    d(allgensize) ".\n"
}

