Sunteți pe pagina 1din 5

Problema 1.

% Testul de inteligenta al lui Einstein


% Reguli:
% a.Britanicul locuieste in casa rosie
% b.Suedezul are un caine
% c.Danezul bea ceai
% d.Casa verde se afla in stanga casei albe
% e.Proprietarul casei verzi bea cafea
% f.Persoana care fumeaza Pall Mall are o pasare
% g.Proprietarul casei din mijloc bea lapte
% h.Proprietarul casei galbene fumeaza Dunhill
% i.Norvegianul locuieste in prima casa
% j.Fumatorul de Marlboro locuieste langa cel care are o pisica
% k.Proprietarul care are un cal locuiste langa cel care fumeaza Dunhill
% l.Fumatorul de Winfield bea bere
% m.Norvegianul locuieste langa casa albastra
% n.Germanul fumeaza Rothmans
% o.Fumatorul de Marlboro are un vecin care bea apa

% membru(X,L) - X este in lista L


membru(X,[X|_]).
membru(X,[_|T]) :-
membru(X,T).

% dreapta(X,Y,L) : Y se afla in dreapta lui X in lista L


dreapta(L, R, [L | [R | _]]).
dreapta(L, R, [_ | Rest]) :- dreapta(L, R, Rest).

% langa(X,Y,L) : X se afla langa Y in lista L


langa(X, Y, List) :- dreapta(X, Y, List).
langa(X, Y, List) :- dreapta(Y, X, List).

einstein(Case, Prop_Peste) :-
=(Case, [[casa, norvegian, _, _, _, _], _, [casa, _, _, _, lapte, _], _, _]),
membru([casa, britanic, _, _, _, rosu], Case),
membru([casa, suedez, caine, _, _, _], Case),
membru([casa, danez, _, _, ceai, _], Case),
dreapta([casa, _, _, _, _, verde], [casa, _, _, _, _, alb], Case),
membru([casa, _, _, _, cafea, verde], Case),
membru([casa, _, pasare, pallmall, _, _], Case),
membru([casa, _, _, dunhill, _, galben], Case),
langa([casa, _, _, marlboro, _, _], [casa, _, pisica, _, _, _], Case),
langa([casa, _, _, dunhill, _, _], [casa, _, cal, _, _, _], Case),
membru([casa, _, _, winfield, bere, _], Case),
langa([casa, norvegian, _, _, _, _], [casa, _, _, _, _, albastru], Case),
membru([casa, german, _, rothmans, _, _], Case),
langa([casa, _, _, marlboro, _, _], [casa, _, _, _, apa, _], Case),
membru([casa, Prop_Peste, peste, _, _, _], Case).

Interogare:
| ?- einstein(Case,Prop_Peste) .
Case = [[casa,norvegian,pisica,dunhill,apa,galben],
[casa,danez,cal,marlboro,ceai,albastru],
[casa,britanic,pasare,pallmall,lapte,rosu],
[casa,german,peste,rothmans,cafea,verde],
[casa,suedez,caine,winfield,bere,alb]],
Prop_Peste = german ?
Yes

Problema 2.

Problema pestelui a lui Einstein


There are five houses in five different colours starting from left to right. In each houselives a
person of a different nationality.
These owners all drink a certain type of beverage,smoke a certain brand of cigarette and keep a
certain type of pet. No two owners have thesame pet, smoke the same brand or drink the same
beverage. The question is: WHOOWNS THE FISH??? Hints:
1 The Brit lives in the red house
2. The Swede keeps dogs as pets
3. The Dane drinks tea
4. The green house is on the left of the white house
5. The green house's owner drinks coffee
6. The person who smokes Pall Mall rears birds
7. The owner of the yellow house smokes Dunhill
8. The man living in the centre house drinks milk
9. The Norwegian lives in the first house
10. The person who smokes Marlboro lives next to the one who keeps cats
11. The person who keeps horses lives next to the person who smokes Dunhill
12. The person who smokes Winfield drinks beer
13. The German smokes Rothmans
14. The Norwegian lives next to the blue house
15. The person who smokes Marlboro has a neigbor who drinks water
==
REZOLVARE SISCTUS PROLOG

% Einstein's Riddle

member(X,[X|T]).
member(X,[H|T]):-member(X,T).

next_to(X, Y, List) :- iright(X, Y, List).


next_to(X, Y, List) :- iright(Y, X, List).
iright(L, R, [L | [R | _]]).
iright(L, R, [_ | Rest]) :- iright(L, R, Rest).
einstein(Houses, Fish_Owner) :-
=(Houses, [[house, norwegian, _, _, _, _], _, [house, _, _, _, milk, _], _, _]),
member([house, brit, _, _, _, red], Houses),
member([house, swede, dog, _, _, _], Houses),
member([house, dane, _, _, tea, _], Houses),
iright([house, _, _, _, _, green], [house, _, _, _, _, white], Houses),
member([house, _, _, _, coffee, green], Houses),
member([house, _, bird, pallmall, _, _], Houses),
member([house, _, _, dunhill, _, yellow], Houses),
next_to([house, _, _, dunhill, _, _], [house, _, horse, _, _, _], Houses),
member([house, _, _, _, milk, _], Houses),
next_to([house, _, _, marlboro, _, _], [house, _, cat, _, _, _], Houses),
next_to([house, _, _, marlboro, _, _], [house, _, _, _, water, _], Houses),
member([house, _, _, winfield, beer, _], Houses),
member([house, german, _, rothmans, _, _], Houses),
next_to([house, norwegian, _, _, _, _], [house, _, _, _, _, blue], Houses),
member([house, Fish_Owner, fish, _, _, _], Houses).

Problema 3:
Maria
Enuntul problemei:
Avem o fetita, Maria în bucatarie.
Pe poliţa de sus se afla ciocolata.
Maria vrea sa ia ciocolata dar nu poate ajunge pana la ea.
In camera se mai afla o cutie, pozitionatã in dreptul ferestrei pe care maimuta o poate folosi.
Maria poate realiza urmãtoarele actiuni :
-sã meargã pe podea
-sã se urce pe cutie
-sã împingã cutia
-sã ia ciocolata dacã stã pe cutie chiar langa poliţă
Poate Maria să ia ciocolata ?
Codul în Prolog:

%starile

stare(la_usa, pe_podea , la_fereastra , nu_are).


stare(la_mijloc, pe_podea, la_fereastra, nu_are).
stare(la_fereastra, pe_podea, la_fereastra , nu_are).
stare(la_fereastra, pe_cutie, la_fereastra, nu_are).
stare(mijloc, pe_podea, mijloc, nu_are).
stare(mijloc, pe_cutie, mijloc, nu_are).
stare(mijloc, pe_cutie, mijloc, are).
%miscarile

miscare(stare(mijloc, pe_cutie, mijloc, nu_are),


ia,
stare(mijloc, pe_cutie, mijloc , are)).

miscare(stare(P, pe_podea, P, H),


urca,
stare(P, pe_cutie, P, H)).

miscare(stare(P1, pe_podea, P1, H),


impinge,
stare(P2, pe_podea, P2, H)).

miscare(stare(P1,pe_podea,B,H),
merge(P1,P2),
stare(P2,pe_podea,B,H)).

%poate lua

poate_lua(stare(_,_,_,are)).
poate_lua(Stare1):- miscare(Stare1,M,Stare2),poate_lua(Stare2).
Interogãri:

| ?- poate_lua(stare(la_usa, pe_podea, la_fereastra, nu_are)).

Yes

| ?- poate_lua(stare(la_usa, pe_podea, mijloc, are)).

Yes
| ?- poate_lua(stare(la_fereastra, pe_cutie, la_fereastra, nu_are)).

no

S-ar putea să vă placă și