Wednesday, 23 October 2024

sffknfsfnsdks

 https://docs.google.com/document/d/16HPy3uJ1LrfLFnviRVVPnavEK-9SBM-FN1lxuYoxSE0/edit?tab=t.0



% male 

male(raj).

male(rahul).

male(sanjeev).

male(sam).

male(evan).


% female

female(neha).

female(elizabeth).

female(uli).

female(nupur).


% facts

parent(raj, rahul).

parent(raj, sanjeev).

parent(neha, rahul).

parent(neha, sanjeev).


parent(rahul, sam).

parent(elizabeth, sam).


parent(sanjeev, nupur).

parent(uli, nupur).


parent(sanjeev, evan).

parent(uli, evan).


% wife facts

wife(neha, raj).

wife(elizabeth, rahul).

wife(uli, sanjeev).



% rules

siblings(X, Y) :- parent(Z, X), parent(Z, Y), X \== Y.

husband(X, Y) :- wife(Y, X). 

father(X, Y) :- male(X), parent(X, Y).

mother(X, Y) :- female(X), parent(X, Y).

grandparent(X, Y) :- parent(X, Z), parent(Z, Y).





% Base case: If there is only 1 disk, just move it from Source to Destination.

move(1, Source, Destination, _) :-

    write('Move disk 1 from '), write(Source), write(' to '), write(Destination), nl.


% Recursive case: Move N disks from Source to Destination using Auxiliary.

move(N, Source, Destination, Auxiliary) :-

    N > 1,

    M is N - 1,

    

    % Step 1: Move N-1 disks from Source to Auxiliary using Destination as the helper

    move(M, Source, Auxiliary, Destination),

    

    % Step 2: Move the Nth disk from Source to Destination

    write('Move disk '), write(N), write(' from '), write(Source), write(' to '), write(Destination), nl,

    

    % Step 3: Move N-1 disks from Auxiliary to Destination using Source as the helper

    move(M, Auxiliary, Destination, Source).


% Facts

mammal(horse).         % Horses are mammals

mammal(cow).           % Cows are mammals

mammal(pig).           % Pigs are mammals

horse(bluebird).       % Bluebird is a horse

can_read(X) :- literate(X).  % Whoever can read is literate

beside_lake(tree(T)) :- aquatic_bird_sleeps_in(T).  % Any tree where aquatic birds sleep is beside some lake


% Rule for food

food(X) :- eats(Y, X), \+ killed_by(Y, X).  % Anything someone eats and is not killed by is food


% Queries to prove:

% ?- mammal(horse).

% ?- horse(bluebird).

% ?- literate(X).

% ?- beside_lake(tree(T)).

% ?- food(X).




% Facts

hungry(rimi).        % Rimi is hungry


% Rules

barking(X) :- hungry(X).      % If X is hungry, then X barks

angry(raja) :- barking(rimi). % If Rimi is barking, then Raja is angry


% Query (to prove that Raja is angry)

% ?- angry(raja).