Zebra puzzle

You are encouraged to solve this task according to the task description, using any language you may know.
The Zebra puzzle, a.k.a. Einstein's Riddle,
is a logic puzzle which is to be solved programmatically.



It has several variants, one of them this:

   There are five houses.
   The English man lives in the red house.
   The Swede has a dog.
   The Dane drinks tea.
   The green house is immediately to the left of the white house.
   They drink coffee in the green house.
   The man who smokes Pall Mall has birds.
   In the yellow house they smoke Dunhill.
   In the middle house they drink milk.
   The Norwegian lives in the first house.
   The man who smokes Blend lives in the house next to the house with cats.
   In a house next to the house where they have a horse, they smoke Dunhill.
   The man who smokes Blue Master drinks beer.
   The German smokes Prince.
   The Norwegian lives next to the blue house.
   They drink water in a house next to the house where they smoke Blend. 

The question is, who owns the zebra?

Additionally, list the solution for all the houses.

Optionally, show the solution is unique.



Related tasks

   Dinesman's multiple-dwelling problem
   Twelve statements


CONTENT = { House:       '',
            Nationality: %i[English Swedish Danish Norwegian German],
            Colour:      %i[Red Green White Blue Yellow],
            Pet:         %i[Dog Birds Cats Horse Zebra],
            Drink:       %i[Tea Coffee Milk Beer Water],
            Smoke:       %i[PallMall Dunhill BlueMaster Prince Blend] }
 
def adjacent? (n,i,g,e)
  (0..3).any?{|x| (n[x]==i and g[x+1]==e) or (n[x+1]==i and g[x]==e)}
end
 
def leftof? (n,i,g,e)
  (0..3).any?{|x| n[x]==i and g[x+1]==e}
end
 
def coincident? (n,i,g,e)
  n.each_index.any?{|x| n[x]==i and g[x]==e}
end
 
def solve_zebra_puzzle
  CONTENT[:Nationality].permutation{|nation|
    next unless nation.first == :Norwegian                              # 10
    CONTENT[:Colour].permutation{|colour|
      next unless leftof?(colour, :Green, colour, :White)               # 5
      next unless coincident?(nation, :English, colour, :Red)           # 2
      next unless adjacent?(nation, :Norwegian, colour, :Blue)          # 15
      CONTENT[:Pet].permutation{|pet|
        next unless coincident?(nation, :Swedish, pet, :Dog)            # 3
        CONTENT[:Drink].permutation{|drink|
          next unless drink[2] == :Milk                                 # 9
          next unless coincident?(nation, :Danish, drink, :Tea)         # 4
          next unless coincident?(colour, :Green, drink, :Coffee)       # 6
          CONTENT[:Smoke].permutation{|smoke|
            next unless coincident?(smoke, :PallMall, pet, :Birds)      # 7
            next unless coincident?(smoke, :Dunhill, colour, :Yellow)   # 8
            next unless coincident?(smoke, :BlueMaster, drink, :Beer)   # 13
            next unless coincident?(smoke, :Prince, nation, :German)    # 14
            next unless adjacent?(smoke, :Blend, pet, :Cats)            # 11
            next unless adjacent?(smoke, :Blend, drink, :Water)         # 16
            next unless adjacent?(smoke, :Dunhill,pet, :Horse)          # 12
            print_out(nation, colour, pet, drink, smoke)
  } } } } }
end
 
def print_out (nation, colour, pet, drink, smoke)
  width = CONTENT.map{|x| x.flatten.map{|y|y.size}.max}
  fmt = width.map{|w| "%-#{w}s"}.join(" ")
  national = nation[ pet.find_index(:Zebra) ]
  puts "The Zebra is owned by the man who is #{national}",""
  puts fmt % CONTENT.keys, fmt % width.map{|w| "-"*w}
  [nation,colour,pet,drink,smoke].transpose.each.with_index(1){|x,n| puts fmt % [n,*x]}
end
 
solve_zebra_puzzle