Einstein Riddle using Prolog

I'm trying to solve the Einstein riddle using Prolog. When I'm trying to run by houses(Hs), it shows No. Task is

<ol> <li>The Brit lives in the red house. </li> <li>The Swede keeps dogs as pets. </li> <li>The Dane drinks tea.</li> <li>The green house is on the immediate left of the white house. </li> <li>The green house's owner drinks coffee. </li> <li>The owner who smokes Pall Mall rears birds. </li> <li>The owner of the yellow house smokes Dunhill. </li> <li>The owner living in the center house drinks milk. </li> <li>The Norwegian lives in the first house. </li> <li>The owner who smokes Blends lives next to the one who keeps cats. </li> <li>The owner who keeps the horse lives next to the one who smokes Dunhill.</li> <li>The owner who smokes Bluemasters drinks beer. </li> <li>The German smokes Prince. </li> <li>The Norwegian lives next to the blue house. </li> <li>The owner who smokes Blends lives next to the one who drinks water.</li> </ol>
    houses(Hs) :-
       length(Hs, 5),                                            
       member(h(english,_,_,_,red), Hs),                         
       member(h(swede,dog,_,_,_), Hs),                         
       member(h(_,_,_,coffee,green), Hs),                        
       member(h(dane,_,_,tea,_), Hs),                       
       next(h(_,_,_,_,green), h(_,_,_,_,white), Hs),             
       member(h(_,bird,'Pall Mall',_,_), Hs),                       
       member(h(_,_,'Dunhill',_,yellow), Hs),                         
       Hs = [_,_,h(_,_,_,milk,_),_,_],                           
       Hs = [h(norwegian,_,_,_,_)|_],                            
       next(h(_,horse,_,_,_), h(_,_,'Dunhill',_,_), Hs),        
       next(h(_,_,blend,_,_), h(_,cat,_,_,_), Hs),             
       member(h(_,_,'Blue Master',beer,_), Hs),                        
       member(h(german,_,'Prince',_,_), Hs),                      
       next(h(norwegian,_,_,_,_), h(_,_,_,_,blue), Hs),  
       next(h(_,_,'Blend',_,_), h(_,_,_,water,_), Hs), 
       member(h(_,fish,_,_,_), Hs).

    next(A, B, Ls) :- append(_, [A,B|_], Ls).
    next(A, B, Ls) :- append(_, [B,A|_], Ls).

I have no idea what is wrong. Thanks


Here is a <strong>generalization</strong> of your program. I added some extra * to remove several goals and replaced some terms by _/*origterm*/. And yet, the resulting program is still failing. Therefore, the error <strong>has to be</strong> in the remaining fragment. You did not say anything about the program (Edit: you added something later), so I do not (Edit: want to) know what it is about. But no matter what, the error has to be in the remaining visible part:

:- initialization(houses(_Sol)).
:- op(950, fy, *).

houses(Hs) :-
   length(Hs, 5),
   * <s>member(h(english,_,_,_,red), Hs)</s>,                         %  2
   * <s>member(h(swede,dog,_,_,_), Hs)</s>,
   * <s>member(h(_,_,_,coffee,green), Hs)</s>,
   * <s>member(h(dane,_,_,tea,_), Hs)</s>,
   * <s>next(h(_,_,_,_,green), h(_,_,_,_,white), Hs)</s>,
   member(h(_,_<s>/*bird*/</s>,'Pall Mall',_,_), Hs),
   member(h(_,_,'Dunhill',_,_<s>/*yellow*/</s>), Hs),
   * <s>Hs = [_,_,h(_,_,_,milk,_),_,_]</s>,
   * <s>Hs = [h(norwegian,_,_,_,_)|_]</s>,
   * <s>next(h(_,horse,_,_,_), h(_,_,'Dunhill',_,_), Hs)</s>,
   next(h(_,_,blend,_,_), _<s>/*h(_,cat,_,_,_)*/</s>, Hs),
   member(h(_,_,'Blue Master',_<s>/*beer*/</s>,_), Hs),
   member(h(_<s>/*german*/</s>,_,'Prince',_,_), Hs),
   * <s>next(h(norwegian,_,_,_,_), h(_,_,_,_,blue), Hs)</s>,
   next(h(_,_,'Blend',_,_), _<s>/*h(_,_,_,water,_)*/</s>, Hs),
   * <s>member(h(_,fish,_,_,_), Hs)</s>.

next(A, B, Ls) :- append(_, [A,B|_], Ls).
next(A, B, Ls) :- append(_, [B,A|_], Ls).

There is not much left! In the visible part there is at least one error! (And, strictly speaking there may be many more errors in the other parts. We simply don't know).


  • Spring 3.0 RESTful Controller Fails on Redirect
  • Python web crawler sometimes returns half of the source code, sometimes all of it… From the same web
  • Different results for 2 subset data methods in R
  • jQuery move div left on click then right on click
  • Reflecting a decorator pattern in mysql database table
  • Custom views not loading in production mode, but load in development
  • Mechanize on Ruby 1.9.3 encoding issue
  • CoffeeScript : unexpected INDENT error
  • Is the Rails 4.2 app taking too much memory?
  • Where do I put my extension method?
  • Download a file from an FTP using Curl with PHP
  • How to use 'defuse/php-encryption'?
  • PHP: Merge/Add multi-dimensional array?
  • Simple promise example with bluebird and coffeescript works half the time
  • jQuery plugin Validate : revalidate as typing / mouse focus
  • Take Screenshot of a UIImage iOS
  • Internal link in email?
  • Display images from an array [duplicate]
  • How can I customize this build script with Node?
  • Simple promise example with bluebird and coffeescript works half the time
  • Which regular expression is able to select excel column names in a formula in C#?
  • Python->Beautifulsoup->Webscraping->Looping over URL (1 to 53) and saving Results
  • Is there a way to disable drag&drop in dashing?
  • Einstein Riddle using Prolog
  • XPath Exclude Text From Child Element
  • Google Places Autocomplete, filter by establishments/restaurants
  • Could we use owl:sameAs in an OWL restriction?
  • Hide without creating empty row
  • Rails gemfile editing
  • Template is missing error even if I have done a redirect_to in the controller
  • Can I have the market update an app that was installed from else where?
  • Simple test app deploys to Heroku but won't run
  • Java : How to tint this PNG programmatically?
  • Flex items with same property values are rendering in different sizes
  • Plotting densities in R
  • How to split circle in to the sectors in google maps?
  • Update Google Maps traffic layer without page reloading
  • Installing iPhone App to iPhone
  • How to modify the colors in the legend of a plot using a fill gradient?
  • JTable with a ScrollPane misbehaving