Same-generation problem

Given the parent relationship (an acyclic graph), find all pairs of persons belonging to the same generation. A person a is of the same generation as a person b if (i) either they are siblings, or (ii) or they are children of two persons of the same generation.

INPUT: Relation "parent/2". A fact "parent(frank,georg)" means that frank is a parent of georg.

The "same-generation/2" relation containing all facts of the form same-generation(a,b) such that a is of the  same generation as b.