News for hackers. Stuff that matters.
Re:Logic programming is overrated, at least for logic puzzle... by Jtsummers on Thursday June 01, 2023 @05:31PM (#36157644)

  solution(Pairs, Water, Zebra, Vs) :-
          Table   = [Houses,Nations,Drinks,Smokes,Animals],
          Houses  = [Red,Green,Yellow,Blue,Ivory],
          Nations = [England,Spain,Ukraine,Norway,Japan],
          Names   = [england,spain,ukraine,norway,japan],
          Drinks  = [Coffee,Milk,OrangeJuice,Tea,Water],
          Smokes  = [OldGold,Kools,Chesterfield,LuckyStrike,Parliaments],
          Animals = [Dog,Snails,Horse,Fox,Zebra],
          pairs_keys_values(Pairs, Nations, Names),
          maplist(all_distinct, Table),
          append(Table, Vs),
          Vs ins 1..5,
          England #= Red,               % hint 1
          Spain #= Dog,                 % hint 2
          Coffee #= Green,              % hint 3
          Ukraine #= Tea,               % hint 4
          Green #= Ivory + 1,           % hint 5
          OldGold #= Snails,            % hint 6
          Kools #= Yellow,              % hint 7
          Milk #= 3,                    % hint 8
          Norway #= 1,                  % hint 9
          next_to(Chesterfield, Fox),   % hint 10
          next_to(Kools, Horse),        % hint 11
          LuckyStrike #= OrangeJuice,   % hint 12
          Japan #= Parliaments,         % hint 13
          next_to(Norway, Blue).        % hint 14

  next_to(H, N) :- abs(H-N) #= 1.
It's subjective, but the above is far clearer about the rules to me. Compare `next_to` in both:

  next_to(Kools, Horse)
  next_to(house(_,_,_,_,kools),
          house(_,_,horse,_,_), Houses)
The former is much more straightforward as a representation of the hint. You don't need to know which entry in a `house` corresponds to cigarette brand and animal, you can just directly compare the two and say Kools is next to Horse.

There are no comments on this comment yet.