1 | initial version |
For such a small problem, an easy way to solve this in Sage is to iterate over all possible permutations and return the compatible ones (brute force method). Actually, you only need Python:
sage: from itertools import permutations
sage: Abe, Dan, Mary, Sue = range(4)
sage: ages = [3, 5, 6, 9]
sage: for p in permutations(ages):
....: if p[Abe] > p[Dan] and p[Sue] < p[Mary] and p[Sue] == p[Dan] + 3 and p[Mary] > p[Abe]:
....: print p
(5, 3, 9, 6)