Prolog puzzle solver