From 138610b0709d6e251c16b391242023eec393d775 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 15 Feb 2016 20:17:49 +0100 Subject: Prolog: add a graph of family relations --- prolog/problems/family_relations/ancestor_2/sl.py | 18 +- prolog/problems/family_relations/aunt_2/sl.py | 12 +- prolog/problems/family_relations/brother_2/sl.py | 10 +- prolog/problems/family_relations/cousin_2/sl.py | 15 +- .../problems/family_relations/descendant_2/sl.py | 17 +- prolog/problems/family_relations/famrel.svg | 343 +++++++++++++++++++++ prolog/problems/family_relations/father_2/sl.py | 12 +- .../problems/family_relations/grandparent_2/sl.py | 15 +- prolog/problems/family_relations/mother_2/sl.py | 12 +- prolog/problems/family_relations/sister_2/sl.py | 12 +- prolog/problems/family_relations/sl.py | 8 +- 11 files changed, 431 insertions(+), 43 deletions(-) create mode 100644 prolog/problems/family_relations/famrel.svg diff --git a/prolog/problems/family_relations/ancestor_2/sl.py b/prolog/problems/family_relations/ancestor_2/sl.py index 0308cde..081732b 100644 --- a/prolog/problems/family_relations/ancestor_2/sl.py +++ b/prolog/problems/family_relations/ancestor_2/sl.py @@ -4,13 +4,17 @@ name = 'ancestor/2' slug = 'X je prednik od Y' description = '''\ -

ancestor(?X, ?Y): X je prednik (oče, mama, dedek, …) od Y.

-
-?- ancestor(patricia, X).
-  X = john ;
-  X = michael ;
-  X = michelle.
-
''' +

ancestor(?X, ?Y): X je prednik (oče, mama, babica, +pradedek, …) od Y.

+?- ancestor(patricia, Y).
+  Y = john ;
+  Y = michael ;
+  Y = michelle.
+
+

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = ['''\

Sedaj pa bo potrebna rekurzija... kako lahko problem prevedem na (en korak) manjši problem?

diff --git a/prolog/problems/family_relations/aunt_2/sl.py b/prolog/problems/family_relations/aunt_2/sl.py index 71f774f..81014f4 100644 --- a/prolog/problems/family_relations/aunt_2/sl.py +++ b/prolog/problems/family_relations/aunt_2/sl.py @@ -6,10 +6,14 @@ slug = 'X je teta od Y' description = '''\

aunt(?X, ?Y): X je teta od Y.

-?- aunt(sally, X).
-  X = vanessa ;
-  X = patricia.
-
''' +?- aunt(sally, Y). + Y = vanessa ; + Y = patricia. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = ['''\

Morda lahko uporabiš rešitev kakšne prejšnje naloge?

diff --git a/prolog/problems/family_relations/brother_2/sl.py b/prolog/problems/family_relations/brother_2/sl.py index 6d45111..2d170aa 100644 --- a/prolog/problems/family_relations/brother_2/sl.py +++ b/prolog/problems/family_relations/brother_2/sl.py @@ -7,9 +7,13 @@ description = '''\

brother(?X, ?Y): X je brat od Y.

 ?- brother(jeffrey, X).
-  X = william ;
-  X = sally.
-
''' + Y = william ; + Y = sally. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = [ '''\ diff --git a/prolog/problems/family_relations/cousin_2/sl.py b/prolog/problems/family_relations/cousin_2/sl.py index a5f2b92..5b82305 100644 --- a/prolog/problems/family_relations/cousin_2/sl.py +++ b/prolog/problems/family_relations/cousin_2/sl.py @@ -4,12 +4,17 @@ name = 'cousin/2' slug = 'X je bratranec ali sestrična od Y' description = '''\ -

cousin(?X, ?Y): X je bratranec ali sestrična od Y.

+

cousin(?X, ?Y): X je bratranec ali sestrična od +Y.

-?- cousin(andrew, X).
-  X = vanessa ;
-  X = patricia.
-
''' +?- cousin(andrew, Y). + Y = vanessa ; + Y = patricia. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = ['''\

Verjetno bi se sedaj splačalo uporabiti rešitev kakšne prejšnje naloge?

diff --git a/prolog/problems/family_relations/descendant_2/sl.py b/prolog/problems/family_relations/descendant_2/sl.py index 36231a1..8774ad6 100644 --- a/prolog/problems/family_relations/descendant_2/sl.py +++ b/prolog/problems/family_relations/descendant_2/sl.py @@ -4,13 +4,18 @@ name = 'descendant/2' slug = 'the descendant relation' description = '''\ -

descendant(?X, ?Y): X je potomec (otrok, vnuk, …) od Y.

+

descendant(?X, ?Y): X je potomec (otrok, vnuk, +pravnukinja, …) od Y.

-?- descendant(patricia, X).
-  X = william ;
-  X = tina ;
-  X = thomas.
-
''' +?- descendant(patricia, Y). + Y = william ; + Y = tina ; + Y = thomas. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = ['''\

Brez rekurzije ne bo šlo... kako lahko problem prevedem na (en korak) manjši problem?

diff --git a/prolog/problems/family_relations/famrel.svg b/prolog/problems/family_relations/famrel.svg new file mode 100644 index 0000000..bff500c --- /dev/null +++ b/prolog/problems/family_relations/famrel.svg @@ -0,0 +1,343 @@ + + + + + + +famrel + + +tina + +  tina♀ + + +william + +  william♂ + + +tina->william + + + + +sally + +  sally♀ + + +melanie + +  melanie♀ + + +sally->melanie + + + + +andrew + +  andrew♂ + + +sally->andrew + + + + +joanne + +  joanne♀ + + +steve + +  steve♂ + + +joanne->steve + + + + +jill + +  jill♀ + + +jill->joanne + + + + +vanessa + +  vanessa♀ + + +susan + +  susan♀ + + +vanessa->susan + + + + +patricia + +  patricia♀ + + +john + +  john♂ + + +patricia->john + + + + +michelle + +  michelle♀ + + +estelle + +  estelle♀ + + +george + +  george♂ + + +estelle->george + + + + +helen + +  helen♀ + + +jerry + +  jerry♂ + + +helen->jerry + + + + +elaine + +  elaine♀ + + +anna + +  anna♀ + + +elaine->anna + + + + +kramer + +  kramer♂ + + +elaine->kramer + + + + +margaret + +  margaret♀ + + +nevia + +  nevia♀ + + +margaret->nevia + + + + +alessandro + +  alessandro♂ + + +margaret->alessandro + + + + +ana + +  ana♀ + + +aleksander + +  aleksander♂ + + +ana->aleksander + + + + +luana + +  luana♀ + + +nevia->luana + + + + +daniela + +  daniela♀ + + +nevia->daniela + + + + +william->vanessa + + + + +william->patricia + + + + +thomas + +  thomas♂ + + +thomas->sally + + + + +thomas->william + + + + +jeffrey + +  jeffrey♂ + + +thomas->jeffrey + + + + +andrew->joanne + + + + +patrick + +  patrick♂ + + +patrick->susan + + + + +john->michelle + + + + +michael + +  michael♂ + + +john->michael + + + + +frank + +  frank♂ + + +frank->george + + + + +george->kramer + + + + +morty + +  morty♂ + + +morty->jerry + + + + +jerry->anna + + + + +aleksandr + +  aleksandr♂ + + +aleksandr->aleksander + + + + +aleksander->luana + + + + +aleksander->daniela + + + + + diff --git a/prolog/problems/family_relations/father_2/sl.py b/prolog/problems/family_relations/father_2/sl.py index adb6fd9..4f7f3de 100644 --- a/prolog/problems/family_relations/father_2/sl.py +++ b/prolog/problems/family_relations/father_2/sl.py @@ -8,10 +8,14 @@ description = '''\
 ?- father(thomas, william).
   true.
-?- father(aleksander, X).
-  X = luana ;
-  X = daniela.
-
''' +?- father(aleksander, Y). + Y = luana ; + Y = daniela. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = [ '''\ diff --git a/prolog/problems/family_relations/grandparent_2/sl.py b/prolog/problems/family_relations/grandparent_2/sl.py index bd2d63c..2961ffa 100644 --- a/prolog/problems/family_relations/grandparent_2/sl.py +++ b/prolog/problems/family_relations/grandparent_2/sl.py @@ -4,14 +4,19 @@ name = 'grandparent/2' slug = 'X je dedek ali babica od Y' description = '''\ -

grandparent(?X, ?Y): X je dedek ali babica od Y.

+

grandparent(?X, ?Y): X je dedek ali babica od +Y.

-?- grandparent(tina, X).
-  X = vanessa ;
-  X = patricia.
+?- grandparent(tina, Y).
+  Y = vanessa ;
+  Y = patricia.
 ?- grandparent(tina, vanessa).
   true.
-
''' + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = ['''\

Dedek ali babica ima otroka, ki ima otroka.

diff --git a/prolog/problems/family_relations/mother_2/sl.py b/prolog/problems/family_relations/mother_2/sl.py index 32103a8..e3cbd1e 100644 --- a/prolog/problems/family_relations/mother_2/sl.py +++ b/prolog/problems/family_relations/mother_2/sl.py @@ -8,10 +8,14 @@ description = '''\
 ?- mother(tina, william).
   true.
-?- mother(nevia, X).
-  X = luana ;
-  X = daniela.
-
''' +?- mother(nevia, Y). + Y = luana ; + Y = daniela. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = [ '''\ diff --git a/prolog/problems/family_relations/sister_2/sl.py b/prolog/problems/family_relations/sister_2/sl.py index 92ea45d..6c36bce 100644 --- a/prolog/problems/family_relations/sister_2/sl.py +++ b/prolog/problems/family_relations/sister_2/sl.py @@ -4,11 +4,15 @@ name = 'sister/2' slug = 'X je sestra od Y' description = '''\ -

sister(?X, ?Y): X je sestra od Y.

+

sister(?X, ?Y): X je sestra od Y. Primer:

-?- sister(vanessa, X).
-  X = patricia.
-
''' +?- sister(vanessa, Y). + Y = patricia. + +

Družinska drevesa so +podana s predikati parent/2, male/1 in +female/1.

+''' plan = [ '''\ diff --git a/prolog/problems/family_relations/sl.py b/prolog/problems/family_relations/sl.py index fafdeef..81242ed 100644 --- a/prolog/problems/family_relations/sl.py +++ b/prolog/problems/family_relations/sl.py @@ -1,2 +1,8 @@ name = 'Družinske relacije' -description = 'Prvi koraki v prologu, pisanje pravil za različne družinske relacije.' +description = '''\ +

Prvi koraki v prologu – pisanje pravil za različne družinske relacije. +Za naloge v tem sklopu je že definirana baza podatkov o +družinskih drevesih. +V prologu so te informacije predstavljene s predikati parent/2, +male/1 in female/1.

+''' -- cgit v1.2.1