dinesmans(X) :-
    %% Baker, Cooper, Fletcher, Miller, and Smith live on different floors 
    %% of an apartment house that contains only five floors. 
    Domain = [1,2,3,4,5],

    %% Baker does not live on the top floor. 
    select(Baker,Domain,D1), Baker =\= 5,

    %% Cooper does not live on the bottom floor.
    select(Cooper,D1,D2), Cooper =\= 1,

    %% Fletcher does not live on either the top or the bottom floor.
    select(Fletcher,D2,D3), Fletcher =\= 1, Fletcher =\= 5,

    %% Miller lives on a higher floor than does Cooper. 
    select(Miller,D3,D4), Miller > Cooper,

    %% Smith does not live on a floor adjacent to Fletcher's.
    select(Smith,D4,_), 1 =\= abs(Smith - Fletcher),

    %% Fletcher does not live on a floor adjacent to Cooper's.
    1 =\= abs(Fletcher - Cooper),

    %% Where does everyone live?
    X = ['Baker'(Baker), 'Cooper'(Cooper), 'Fletcher'(Fletcher), 
         'Miller'(Miller), 'Smith'(Smith)].

main :-  bagof( X, dinesmans(X), L ) 
         -> maplist( writeln, L), nl, write('No more solutions.') 
         ;  write('No solutions.').