Prolog: 3 exam task