Реализация отношений n-юродная тетя и внучка на ТуПролог (тот же турбо) - Prolog
Формулировка задачи:
Вот, чтто у меня получилось, но я не понимаю сам принцип Кто будет Н-юродной тетей, и Н-юродной внучкой... Хелп ми=) Учитель что то говорил про выражение через Н-юродную сестру\брата, их я выразил но как дальше не врубаю...
Извините, не знаю как тут править, внес пару изменений и кажись допер как реализовать н-тетю, но до сих пор не могу понять про внучку...
Решение задачи: «Реализация отношений n-юродная тетя и внучка на ТуПролог (тот же турбо)»
textual
Листинг программы
domains s = string predicates man (s) woman (s) mother (s, s) father (s, s) parent (s, s) married (s, s) mar (s, s) wife (s, s) husband (s, s) sister (s, s) brother (s, s) niece (s, s) nephew (s, s) aunt (s, s) uncle (s, s) grandmother (s, s) grandfather (s, s) granddaughter (s, s) grandson (s, s) cousina (s, s) cousin (s, s) son (s, s) daughter (s, s) greatgrandson (s, s) greatgranddaughter (s, s) n_parent(integer,s,s) n_granddaughter(integer,s,s) t_niece(s,s) t_nephew(s,s) t_sister(s,s) t_brother(s,s) clauses man ("Igor"). man ("Dmitrii2"). man ("Nicolai"). man ("Victor"). man ("Ivan"). man ("Alexcander"). man ("Nicolai_m"). man ("Andrey"). man ("Dmitrii1"). man ("Stepan"). man ("Pavel"). man ("Maksim"). man ("Boris"). man ("Urii"). man ("Semen"). man ("Sergey"). man ("Efim"). man ("Adam"). man ("Roman"). man ("Anton"). man ("Elisei"). man ("Egor"). man ("Mark"). man ("Tixon"). woman ("Elena"). woman ("Marina"). woman ("Jana"). woman ("Alice"). woman ("Vera"). woman ("Alla"). woman ("Nika"). woman ("Gera"). woman ("Mila"). woman ("Tina"). woman ("Lia"). woman ("Lana"). woman ("Lydia"). woman ("Ekaterina"). woman ("Tatiana"). woman ("Maria"). woman ("Svetlana"). woman ("Nora"). woman ("Lubov"). woman ("Valentina"). woman ("Anna"). woman ("Irina"). parent ("Tatiana", "Andrey"). parent ("Tatiana", "Igor"). parent ("Maria", "Tatiana"). parent ("Nora", "Maria"). parent ("Lubov", "Nicolai_m"). parent ("Svetlana", "Dmitrii2"). parent ("Valentina", "Svetlana"). parent ("Anna", "Victor"). parent ("Dmitrii2", "Andrey"). parent ("Dmitrii2", "Igor"). parent ("Nicolai_m", "Tatiana"). parent ("Victor", "Dmitrii2"). parent ("Ivan", "Maria"). parent ("Alexcander", "Nicolai_m"). parent ("Nicolai", "Svetlana"). parent ("Dmitrii1", "Victor"). parent ("Nora", "Ekaterina"). parent ("Ivan", "Ekaterina"). parent ("Elena", "Pavel"). parent ("Stepan", "Pavel"). parent ("Ekaterina", "Maksim"). parent ("Pavel", "Maksim"). parent ("Maksim", "Marina"). parent ("Marina", "Jana"). parent ("Marina", "Boris"). parent ("Irina", "Semen"). parent ("Urii", "Semen"). parent ("Alla", "Vera"). parent ("Sergey", "Vera"). parent ("Vera", "Alice"). parent ("Semen", "Alice"). parent ("Alice", "Marina"). parent ("Efim", "Gera"). parent ("Nika", "Gera"). parent ("Mila", "Anton"). parent ("Elisei", "Anton"). parent ("Anton", "Adam"). parent ("Gera", "Adam"). parent ("Tina", "Mark"). parent ("Egor", "Mark"). parent ("Lia", "Lana"). parent ("Tixon", "Lana"). parent ("Lana", "Lydia"). parent ("Mark", "Lydia"). parent ("Lydia", "Roman"). parent ("Adam", "Roman"). parent ("Roman", "Jana"). parent ("Roman", "Boris"). married ("Tatiana", "Dmitrii2"). married ("Maria", "Nicolai_m"). married ("Svetlana", "Victor"). married ("Nora", "Ivan"). married ("Lubov", "Alexcander"). married ("Valentina", "Nicolai"). married ("Anna", "Dmitrii1"). married ("Elena", "Stepan"). married ("Ekaterina", "Pavel"). married ("Alice", "Maksim"). married ("Marina", "Roman"). married ("Vera", "Semen"). married ("Irina", "Urii"). married ("Alla", "Sergey"). married ("Nika", "Efim"). married ("Mila", "Elisei"). married ("Gera", "Anton"). married ("Tina", "Egor"). married ("Lia", "Tixon"). married ("Lana", "Mark"). married ("Lydia", "Adam"). mar (X,Y):-married(X,Y). mar (X,Y):-married(Y,X). wife (W,X):-woman(W), mar(W,X). husband (H,X):-man(H), mar(H,X). mother (M,X):-parent(M,X), woman(M). father (F,X):-parent(F,X), man(F). sister (S,X):-parent(P,S), parent(P,X), S<>X, woman(S). brother (B,X):-parent(P,B), parent(P,X), B<>X, man(B). niece (N,X):-parent(P,N), sister(P,X), woman(N). niece (N,X):-parent(P,N), brother(P,X), woman(N). nephew (N,X):-parent(P,N), sister(P,X), man(N). nephew (N,X):-parent(P,N), brother(P,X), man(N). aunt (A,X):-niece(X,A), woman(A). aunt (A,X):-nephew(X,A), woman(A). uncle (U,X):-niece(X,U), man(U). uncle (U,X):-nephew(X,U), man(U). grandmother (G,X):-woman(G), parent(P,X), parent(G,P). grandfather (G,X):-man(G), parent(P,X), parent(G,P). granddaughter (G,X):-woman(G), parent(P,G), parent(X,P). grandson (G,X):-man(G), parent(P,G), parent(X,P). cousina (C,X):-woman(C), aunt(A,X), mother(A,C). cousina (C,X):-woman(C), uncle(U,X), father(U,C). cousin (C,X):-man(C), aunt(A,X), mother(A,C). cousin (C,X):-man(C), uncle(U,X), father(U,C). son (S,P):-man(S), parent(P,S). daughter (D,P):-woman(D), parent(P,D). greatgrandson (S,X):-man(S), parent(P,S), parent(Y,P), parent(X,Y). greatgranddaughter(S,X):-woman(S), parent(P,S), parent(Y,P), parent(X,Y). n_granddaughter(N,X,Y):-woman(X),n_parent(N,X,Y). n_parent(1,X,Y):-parent(X,Y). n_parent(N,X,Y):-N>1,parent(X,Z),N1=N-1,n_parent(N1,Z,Y). t_sister(Y,X):-parent(Z,X),parent(F,Z), sister(F,N),parent(N,L), parent(L,Y), woman(Y). t_sister(Y,X):-parent(Z,X),parent(F,Z), brother(F,N),parent(N,L), parent(L,Y), woman(Y). t_brother(Y,X):-parent(Z,X),parent(F,Z), sister(F,N),parent(N,L),parent(L,Y), man(Y). t_brother(Y,X):-parent(Z,X),parent(F,Z), brother(F,N),parent(N,L),parent(L,Y), man(Y). t_niece(Y,X):-t_sister(X,Z), parent(Z,Y), woman(Y). t_niece(Y,X):-t_brother(X,Z), parent(Z,Y), woman(Y). t_nephew(Y,X):-t_brother(X,Z), parent(Z,Y), man(Y). t_nephew(Y,X):-t_sister(X,Z), parent(Z,Y), man(Y).
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д