Prolog implementation of the classic Pirate's Gold riddle