Source: https://lipn.univ-paris13.fr/~pagani/TP_Prolog/tp2_2010(Sol).pdf