# Einstein Riddle
# See https://en.wikipedia.org/wiki/Zebra_Puzzle
#
# There are 15 hints:
#   There are five houses.
#   The Englishman lives in the red house.
#   The Spaniard owns the dog.
#   Coffee is drunk in the green house.
#   The Ukrainian drinks tea.
#   The green house is immediately to the right of the ivory house.
#   The Old Gold smoker owns snails.
#   Kools are smoked in the yellow house.
#   Milk is drunk in the middle house.
#   The Norwegian lives in the first house.
#   The man who smokes Chesterfields lives in the house next to the man with the fox.
#   Kools are smoked in the house next to the house where the horse is kept.
#   The Lucky Strike smoker drinks orange juice.
#   The Japanese smokes Parliaments.
#   The Norwegian lives next to the blue house.
#
# The questions are:
#   Who drinks water?
#   Who owns the fish?

@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <http://example.org/ns#>.

(_:L _:A1 _:A2 _:A3 _:A4 _:A5 _:A6 _:A7 _:A8 _:A9 _:A10 _:A11 _:A12 _:A13 _:A14 _:A15 _:A16 _:A17 _:A18 _:A19 _:A20
 _:A21 _:A22 _:A23 _:A24 _:A25 _:A26 _:A27 _:A28 _:A29 _:A30 _:A31 _:A32 _:A33 _:A34 _:A35 _:A36 _:A37 _:A38 _:A39 _:A40
 _:A41 _:A42 _:A43 _:A44 _:A45 _:A46 _:A47 _:A48 _:A49 _:A50 _:A51 _:A52 _:A53 _:A54 _:A55 _:A56 _:A57 _:A58 _:A59 _:A60
 _:A61 _:A62 _:A63 _:A64 _:A65 _:A66) log:onNegativeSurface {
    _:L log:equalTo ((_:A1 :Norwegian _:A2 _:A3 _:A4) (:blue _:A5 _:A6 _:A7 _:A8) (_:A9 _:A10 _:A11 :milk _:A12) _:A13 _:A14);
    :pair ((_:A15 _:A16 _:A17 _:A18 :Kools) (_:A19 _:A20 :horse _:A21 _:A22));
    :pair ((_:A23 _:A24 :fox _:A25 _:A26) (_:A27 _:A28 _:A29 _:A30 :Chesterfields));
    :sublist ((:ivory _:A31 _:A32 _:A33 _:A34) (:green _:A35 _:A36 :coffee _:A37));
    list:member (:red :Englishman _:A38 _:A39 _:A40);
    list:member (_:A41 :Spaniard :dog _:A42 _:A43);
    list:member (_:A44 :Ukrainian _:A45 :tea _:A46);
    list:member (_:A47 _:A48 :snails _:A49 :Old_Gold);
    list:member (:yellow _:A50 _:A51 _:A52 :Kools);
    list:member (_:A53 _:A54 _:A55 :orange_juice :Lucky_Strike);
    list:member (_:A56 :Japanese _:A57 _:A58 :Parliaments);
    list:member (_:A59 _:A60 _:A61 :water _:A62);
    list:member (_:A63 _:A64 :zebra _:A65 _:A66).
    () log:onNegativeSurface {
        _:A60 :drinks :water.
        _:A64 :owns :zebra.
        :riddle :houses _:L.
    }.
}.

(_:A _:B _:C) log:onNegativeSurface {
    () log:onQuerySurface {
        _:A :pair (_:B _:C).
    }.
    _:A :sublist (_:B _:C).
}.

(_:A _:B _:C) log:onNegativeSurface {
    () log:onQuerySurface {
        _:A :pair (_:B _:C).
    }.
    _:A :sublist (_:C _:B).
}.

(_:A _:B _:C _:D _:E) log:onNegativeSurface {
    () log:onQuerySurface {
        _:A :sublist _:B.
    }.
    (_:C _:D) list:append _:A.
    (_:E _:B) list:append _:C.
}.

# query
(_:A _:B _:C) log:onQuerySurface {
    _:A :drinks :water.
    _:B :owns :zebra.
    :riddle :houses _:C.
}.
