diff options
author | Martin Možina <martin.mozina@fri.uni-lj.si> | 2016-10-25 11:44:37 +0200 |
---|---|---|
committer | Martin Možina <martin.mozina@fri.uni-lj.si> | 2016-10-25 11:44:37 +0200 |
commit | 656c66097e806b4c53646ea1fff3d8615426d304 (patch) | |
tree | 172d4cccd187380bfdc81df3f195f5304d9f4d34 /prolog/problems | |
parent | 0bfa95be7046b101a00f83f082260b5d0e007159 (diff) | |
parent | 9d662ae9b7a84b3826e91d2af17f251daaabcd79 (diff) |
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'prolog/problems')
43 files changed, 808 insertions, 12 deletions
diff --git a/prolog/problems/algol/common.py b/prolog/problems/algol/common.py index 2885432..0085483 100644 --- a/prolog/problems/algol/common.py +++ b/prolog/problems/algol/common.py @@ -1,2 +1,2 @@ id = 1001 -number = 12 +number = 130 diff --git a/prolog/problems/clp_fd/common.py b/prolog/problems/clp_fd/common.py index eec07f0..4f3096c 100644 --- a/prolog/problems/clp_fd/common.py +++ b/prolog/problems/clp_fd/common.py @@ -1,2 +1,2 @@ id = 8 -number = 9 +number = 100 diff --git a/prolog/problems/clp_r/common.py b/prolog/problems/clp_r/common.py index 2238250..fe95da6 100644 --- a/prolog/problems/clp_r/common.py +++ b/prolog/problems/clp_r/common.py @@ -1,2 +1,2 @@ id = 9 -number = 8 +number = 90 diff --git a/prolog/problems/dcg/common.py b/prolog/problems/dcg/common.py index a55cdef..8a0f57f 100644 --- a/prolog/problems/dcg/common.py +++ b/prolog/problems/dcg/common.py @@ -1,2 +1,2 @@ id = 10 -number = 10 +number = 110 diff --git a/prolog/problems/denotational_semantics/common.py b/prolog/problems/denotational_semantics/common.py index 86c7532..9e282d0 100644 --- a/prolog/problems/denotational_semantics/common.py +++ b/prolog/problems/denotational_semantics/common.py @@ -1,2 +1,2 @@ id = 11 -number = 11 +number = 120 diff --git a/prolog/problems/family_relations/common.py b/prolog/problems/family_relations/common.py index 5aff819..611c856 100644 --- a/prolog/problems/family_relations/common.py +++ b/prolog/problems/family_relations/common.py @@ -1,2 +1,2 @@ id = 1 -number = 1 +number = 10 diff --git a/prolog/problems/license_plates/common.py b/prolog/problems/license_plates/common.py index e35a349..42bf4e7 100644 --- a/prolog/problems/license_plates/common.py +++ b/prolog/problems/license_plates/common.py @@ -1,2 +1,2 @@ id = 7 -number = 7 +number = 80 diff --git a/prolog/problems/lists/common.py b/prolog/problems/lists/common.py index 4788fc4..ed64b41 100644 --- a/prolog/problems/lists/common.py +++ b/prolog/problems/lists/common.py @@ -1,2 +1,2 @@ id = 2 -number = 2 +number = 30 diff --git a/prolog/problems/lists_advanced/common.py b/prolog/problems/lists_advanced/common.py index d4e77fa..f25a4a0 100644 --- a/prolog/problems/lists_advanced/common.py +++ b/prolog/problems/lists_advanced/common.py @@ -1,2 +1,2 @@ id = 1000 -number = 3 +number = 40 diff --git a/prolog/problems/sets/common.py b/prolog/problems/sets/common.py index b3335ec..1110721 100644 --- a/prolog/problems/sets/common.py +++ b/prolog/problems/sets/common.py @@ -1,2 +1,2 @@ id = 5 -number = 5 +number = 60 diff --git a/prolog/problems/sorting/common.py b/prolog/problems/sorting/common.py index 4e5aa88..cbe679b 100644 --- a/prolog/problems/sorting/common.py +++ b/prolog/problems/sorting/common.py @@ -1,2 +1,2 @@ id = 3 -number = 4 +number = 50 diff --git a/prolog/problems/trees/common.py b/prolog/problems/trees/common.py index 9cf57f5..7a974d4 100644 --- a/prolog/problems/trees/common.py +++ b/prolog/problems/trees/common.py @@ -1,2 +1,2 @@ id = 6 -number = 6 +number = 70 diff --git a/prolog/problems/world_data/all_capitals_1/common.py b/prolog/problems/world_data/all_capitals_1/common.py new file mode 100644 index 0000000..490c183 --- /dev/null +++ b/prolog/problems/world_data/all_capitals_1/common.py @@ -0,0 +1,44 @@ +from operator import itemgetter +import socket +import prolog.engine +import prolog.util +from server.hints import Hint +import server.problems + +id = 10002 +number = 20 +visible = True +facts = 'mondial' + +solution = '''\ +all_capitals(List) :- + findall(Capital, country(_, _, Capital, _, _, _), List). +''' + +hint_type = { +} + +test_cases = [ + ('all_capitals(X), length(X, L)', [{'L': '244'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit=None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + if n_correct == len(test_cases): + hints += [{'id': 'final_hint'}] + return n_correct, len(test_cases), hints diff --git a/prolog/problems/world_data/all_capitals_1/en.py b/prolog/problems/world_data/all_capitals_1/en.py new file mode 100644 index 0000000..92eb2b2 --- /dev/null +++ b/prolog/problems/world_data/all_capitals_1/en.py @@ -0,0 +1,13 @@ +name = 'all_capitals/1' +slug = 'capital cities' + +description = '''\ +<p><code>all_capitals(List)</code>: <code>List</code> is a list of all capitals in the world.</p> +<pre> +?- all_capitals(List). + List = ['Tirana', 'Athina', 'Skopje', 'Beograd', …] +</pre> +<p>Useful facts are given as <code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/all_capitals_1/sl.py b/prolog/problems/world_data/all_capitals_1/sl.py new file mode 100644 index 0000000..cf3413f --- /dev/null +++ b/prolog/problems/world_data/all_capitals_1/sl.py @@ -0,0 +1,13 @@ +name = 'all_capitals/1' +slug = 'glavna mesta' + +description = '''\ +<p><code>all_capitals(List)</code>: <code>List</code> je seznam vseh glavnih mest na svetu.</p> +<pre> +?- all_capitals(List). + List = ['Tirana', 'Athina', 'Skopje', 'Beograd', …] +</pre> +<p>Uporabna dejstva so podana v obliki <code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/capital_2/common.py b/prolog/problems/world_data/capital_2/common.py new file mode 100644 index 0000000..76fb985 --- /dev/null +++ b/prolog/problems/world_data/capital_2/common.py @@ -0,0 +1,52 @@ +from operator import itemgetter +import socket +import prolog.engine +import prolog.util +from server.hints import Hint +import server.problems + +id = '10001' +number = 10 +visible = True +facts = 'mondial' + +solution = '''\ +capital(Country, Capital) :- + country(Country, _, Capital, _, _, _). +''' + +hint_type = { +} + +test_cases = [ + ("capital('France', X)", [{'X': "'Paris'"}]), + ("capital('Turkmenistan', X)", [{'X': "'Ashgabat'"}]), + ("capital('Cocos Islands', X)", [{'X': "'West Island'"}]), + ("capital(X, 'Basseterre')", [{'X': "'Saint Kitts and Nevis'"}]), + ("capital(X, X)", + [{'X': "'Luxembourg'"}, {'X': "'Monaco'"}, {'X': "'Gibraltar'"}, + {'X': "'Ceuta'"}, {'X': "'Melilla'"}, {'X': "'San Marino'"}, + {'X': "'Hong Kong'"}, {'X': "'Macao'"}, {'X': "'Singapore'"}, + {'X': "'Djibouti'"}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit=None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + if n_correct == len(test_cases): + hints += [{'id': 'final_hint'}] + return n_correct, len(test_cases), hints diff --git a/prolog/problems/world_data/capital_2/en.py b/prolog/problems/world_data/capital_2/en.py new file mode 100644 index 0000000..5ecd2ab --- /dev/null +++ b/prolog/problems/world_data/capital_2/en.py @@ -0,0 +1,13 @@ +name = 'capital/2' +slug = 'capitals' + +description = '''\ +<p><code>capital(X, Y)</code>: <code>Y</code> is the capital city of country <code>X</code>.</p> +<pre> +?- capital('Ireland', M). + Y = 'Dublin'. +</pre> +<p>Useful facts are given as <code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/capital_2/sl.py b/prolog/problems/world_data/capital_2/sl.py new file mode 100644 index 0000000..7b14a70 --- /dev/null +++ b/prolog/problems/world_data/capital_2/sl.py @@ -0,0 +1,13 @@ +name = 'capital/2' +slug = 'glavna mesta' + +description = '''\ +<p><code>capital(X, Y)</code>: država <code>X</code> ima glavno mesto <code>Y</code>.</p> +<pre> +?- capital('Ireland', Y). + Y = 'Dublin'. +</pre> +<p>Uporabna dejstva so podana v obliki <code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/common.py b/prolog/problems/world_data/common.py new file mode 100644 index 0000000..006b9f5 --- /dev/null +++ b/prolog/problems/world_data/common.py @@ -0,0 +1,2 @@ +id = 1002 +number = 20 diff --git a/prolog/problems/world_data/en.py b/prolog/problems/world_data/en.py new file mode 100644 index 0000000..3d3cbaf --- /dev/null +++ b/prolog/problems/world_data/en.py @@ -0,0 +1,8 @@ +name = 'The World Factbook' +description = '''\ +<p> +Let's ask prolog some questions about our world, e.g. through which countries a given river flows or which +two countries are most similar in terms of the size of their populations. For this purpose a database +containing facts about the world has been loaded. The database comes from the almanac "The World Factbook". +</p> +''' diff --git a/prolog/problems/world_data/flows_2/common.py b/prolog/problems/world_data/flows_2/common.py new file mode 100644 index 0000000..a3cf79b --- /dev/null +++ b/prolog/problems/world_data/flows_2/common.py @@ -0,0 +1,51 @@ +from operator import itemgetter +import socket +import prolog.engine +import prolog.util +from server.hints import Hint +import server.problems + +id = 10009 +number = 90 +visible = True +facts = 'mondial' + +solution = '''\ +flows(River, Sea) :- + river(River, _, _, Sea, _, _, _, _, _, _, _, _), + Sea \= null. +flows(River, Sea) :- + river(River, River2, _, _, _, _, _, _, _, _, _, _), + River2 \= null, + flows(River2, Sea). +''' + +hint_type = { +} + +test_cases = [ + ("flows('Rhone', X)", [{'X': "'Mediterranean Sea'"}]), + ("flows(X, 'Java Sea')", [{'X': "'Mahakam'"}, {'X': "'Barito'"}]), + ("flows('Drau', X)", [{'X': "'Black Sea'"}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=2.0, inference_limit=None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + if n_correct == len(test_cases): + hints += [{'id': 'final_hint'}] + return n_correct, len(test_cases), hints diff --git a/prolog/problems/world_data/flows_2/en.py b/prolog/problems/world_data/flows_2/en.py new file mode 100644 index 0000000..f108001 --- /dev/null +++ b/prolog/problems/world_data/flows_2/en.py @@ -0,0 +1,20 @@ +name = 'flows/2' +slug = '' + +description = '''\ +<p><code>flows(X, Y)</code>: the river <code>X</code> flows to sea <code>Y</code>. +The predicate should follow the flow from <code>X</code> through different rivers +until it reaches a sea - for example, Drina flows into Save, which flows into Donau, +ending in the Black Sea:</p> +<pre> +?- flows('Drina', Y). + Y = 'Black Sea'. +</pre> +<p>River data is given by the predicate</p> +<pre> +river(Name, FlowsToRiver, FlowsToLake, FlowsToSea, Length, Area, + SourceLat, SourceLon, SourceElevation, MouthLat, MouthLon). +</pre> +''' + +hint = {} diff --git a/prolog/problems/world_data/flows_2/sl.py b/prolog/problems/world_data/flows_2/sl.py new file mode 100644 index 0000000..ef46f6b --- /dev/null +++ b/prolog/problems/world_data/flows_2/sl.py @@ -0,0 +1,34 @@ +name = 'flows/2' +slug = '' + +description = '''\ +<p><code>flows(X, Y)</code>: reka <code>X</code> se izliva v morje <code>Y</code>. +Predikat naj sledi toku skozi različne reke - Drina se npr. priključi Savi, +ki se priključi Donavi, ki teče v Črno morje, zato naj program odgovori tako:</p> +<pre> +?- flows('Drina', Y). + Y = 'Black Sea'. +</pre> +<p>Podatki o rekah so predstavljeni s predikatom</p> +<pre> +river(Name, FlowsToRiver, FlowsToLake, FlowsToSea, Length, Area, + SourceLat, SourceLon, SourceElevation, MouthLat, MouthLon). +</pre> +<p>Za vsako reko je podan največ en izmed argumentov <code>FlowsToRiver</code>, +<code>FlowsToLake</code> in <code>FlowsToSea</code>, ki pove, v katero reko, +jezero oziroma morje se izliva; ostala dva argumenta pa sta <code>null</code>. +''' + +plan = [ + '''\ +<p>Reke, ki se izlivajo neposredno v morje, lahko dobimo s poizvedbo:</p> +<pre> +?- river(River, _, _, Sea, _, _, _, _, _, _, _, _), Sea \= null. + River = 'Thjorsa', Sea = 'Atlantic Ocean' ; + River = 'Thames', Sea = 'North Sea' ; + … +</pre> +''', +] + +hint = {} diff --git a/prolog/problems/world_data/grant_1/common.py b/prolog/problems/world_data/grant_1/common.py new file mode 100644 index 0000000..8c032a3 --- /dev/null +++ b/prolog/problems/world_data/grant_1/common.py @@ -0,0 +1,50 @@ +from operator import itemgetter +import socket +import prolog.engine +from server.hints import Hint +import server.problems + +id = 10007 +number = 70 +visible = True +facts = 'mondial' + +solution = '''\ +grant(Loc):- + (city(Loc, _, _, _, Lat, _, _) + ; + island(Loc, _, _, _, _, Lat, _)), + number(Lat), + Lat > -38, + Lat < -36. +''' + +test_cases = [ + ("grant(Loc)", + [{'Loc': "'Melbourne'"}, {'Loc': "'Auckland'"}, {'Loc': "'Hamilton'"}, {'Loc': "'Santa Rosa'"}, + {'Loc': "'Concepción'"}, {'Loc': "'Talcahuano'"}, {'Loc': "'Tristan Da Cunha'"}]), + ("\+ grant('Ljubljana')", + [{}]), + ("grant('Tristan Da Cunha')", + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit = None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/world_data/grant_1/en.py b/prolog/problems/world_data/grant_1/en.py new file mode 100644 index 0000000..20ad118 --- /dev/null +++ b/prolog/problems/world_data/grant_1/en.py @@ -0,0 +1,15 @@ +name = 'grant/1' +slug = 'Otroka kapitana Granta' + +description = '''\ +<p>Otroka kapitana Granta, tako pravi Jules Verne, sta našla njegovo pismo v steklenici. Izgubil naj bi se v +brodolomu nekje na morju. Vse kar vesta o njegovi lokaciji je, da leži na 37 poldnevniku južne širine. Povprašaj +prolog v katerem mestu ali na katerem otoku se lahko nahaja, da ga rešimo. Privzemimo, da poiščemo vse +lokacije med -36 in -38 stopinjami južne širine (minus ker je pod ekvatorjem).</p> +<p><code>grant(Location)</code>: predikat eno po eno vrne vse lokacije <code>Location</code>, ki ustrezajo +pogojem. <code>Location</code> predstavlja <em>ime</em> lokacije.</p> +<p>Prav ti znajo priti podatki v obliki <code>city(Name, CountryCode, Province, Population, Latitude, Longitude, +Elevation)</code> in <code>island(Name, Group, Area, Elevation, Type, Latitude, Longitude)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/grant_1/sl.py b/prolog/problems/world_data/grant_1/sl.py new file mode 100644 index 0000000..20ad118 --- /dev/null +++ b/prolog/problems/world_data/grant_1/sl.py @@ -0,0 +1,15 @@ +name = 'grant/1' +slug = 'Otroka kapitana Granta' + +description = '''\ +<p>Otroka kapitana Granta, tako pravi Jules Verne, sta našla njegovo pismo v steklenici. Izgubil naj bi se v +brodolomu nekje na morju. Vse kar vesta o njegovi lokaciji je, da leži na 37 poldnevniku južne širine. Povprašaj +prolog v katerem mestu ali na katerem otoku se lahko nahaja, da ga rešimo. Privzemimo, da poiščemo vse +lokacije med -36 in -38 stopinjami južne širine (minus ker je pod ekvatorjem).</p> +<p><code>grant(Location)</code>: predikat eno po eno vrne vse lokacije <code>Location</code>, ki ustrezajo +pogojem. <code>Location</code> predstavlja <em>ime</em> lokacije.</p> +<p>Prav ti znajo priti podatki v obliki <code>city(Name, CountryCode, Province, Population, Latitude, Longitude, +Elevation)</code> in <code>island(Name, Group, Area, Elevation, Type, Latitude, Longitude)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/holiday_2/common.py b/prolog/problems/world_data/holiday_2/common.py new file mode 100644 index 0000000..0ccf8c2 --- /dev/null +++ b/prolog/problems/world_data/holiday_2/common.py @@ -0,0 +1,49 @@ +from operator import itemgetter +import socket +import prolog.engine +from server.hints import Hint +import server.problems + +id = 10005 +number = 50 +visible = True +facts = 'mondial' + +solution = '''\ +holiday(Country, Neighbour):- + country(Country,CC1,_,_,_,_), + (borders(CC1,CC2,_) ; borders(CC2,CC1,_)), + once(geo_sea(_,CC2,_)), + country(Neighbour,CC2,_,_,_,_). +''' + +test_cases = [ + ("holiday('Slovenia', N)", + [{'N': "'Italy'"}, {'N': "'Croatia'"}]), + ("holiday(C, 'Canada')", + [{'C': "'United States'"}]), + ("holiday('Venezuela', 'Guyana')", + [{}]), + ("\+ holiday('Uzbekistan', _)", + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit = None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/world_data/holiday_2/en.py b/prolog/problems/world_data/holiday_2/en.py new file mode 100644 index 0000000..ecb248a --- /dev/null +++ b/prolog/problems/world_data/holiday_2/en.py @@ -0,0 +1,17 @@ +name = 'holiday/2' +slug = 'V katero sosednjo državo gremo lahko na morje?' + +description = '''\ +<p>V katero <em>sosednjo</em> državo gremo lahko na morje?</p> +<p><code>holiday(Country, Neighbour)</code>: <code>Neighbour</code> je sosednja država od <code>Country</code>, +ki ima morje.</p> +<pre> +?- holiday('Slovenia', Neighbour). + Neighbour = 'Italy' ; + Neighbour = 'Croatia' +</pre> +<p>Prav ti znajo priti podatki v obliki <code>borders(Country1, Country2, LenOfBorder)</code> in +<code>geo_sea(Sea, CountryCode, Province)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/holiday_2/sl.py b/prolog/problems/world_data/holiday_2/sl.py new file mode 100644 index 0000000..ecb248a --- /dev/null +++ b/prolog/problems/world_data/holiday_2/sl.py @@ -0,0 +1,17 @@ +name = 'holiday/2' +slug = 'V katero sosednjo državo gremo lahko na morje?' + +description = '''\ +<p>V katero <em>sosednjo</em> državo gremo lahko na morje?</p> +<p><code>holiday(Country, Neighbour)</code>: <code>Neighbour</code> je sosednja država od <code>Country</code>, +ki ima morje.</p> +<pre> +?- holiday('Slovenia', Neighbour). + Neighbour = 'Italy' ; + Neighbour = 'Croatia' +</pre> +<p>Prav ti znajo priti podatki v obliki <code>borders(Country1, Country2, LenOfBorder)</code> in +<code>geo_sea(Sea, CountryCode, Province)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/intro_sl.html b/prolog/problems/world_data/intro_sl.html new file mode 100644 index 0000000..2d27780 --- /dev/null +++ b/prolog/problems/world_data/intro_sl.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html lang="sl"> +<head> + <meta charset="utf-8" /> + <title>Prolog: države sveta</title> + <link rel="stylesheet" type="text/css" href="/css/codeq.css" /> + <link rel="stylesheet" type="text/css" href="../../style.css" /> +</head> +<body> + +<h1>Prolog: države sveta</h1> +<p> +Podatkovna baza za ta sklop vsebuje podatke o državah in geografskih +značilnostih iz <em>CIA World Factbook</em>. Dejstva so podana z naslednjimi predikati: +</p> + +<pre> +country(Name, Code, Capital, Province, Area, Population) +population(CountryCode, GrowthRate, Births) +economy(CountryCode, GDP, Agriculture, Services, Industry, GDPperCapita, Inflation, Unemployment) +language(CountryCode, Language, Percentage) +ethnicGroup(CountryCode, Ethnicity, Percentage) +religion(CountryCode, Religion, Percentage) +borders(CountryCode1, CountryCode2, Length) +continent(Name, Area) +encompasses(CountryCode, Continent, Percentage) +city(Name, CountryCode, Province, Population, Latitude, Longitude, Elevation) +cityothername(Name, CountryCode, Province, OtherName) +province(Name, CountryCode, Population, Area, Capital, CapitalProvince) +provinceothername(Name, CountryCode, OtherName) +sea(Name, Depth) +river(Name, FlowsToRiver, FlowsToLake, FlowsToSea, Length, Basin, + SourceLatitude, SourceLongitude, SourceName, SourceElevation, + MouthLatitude, MouthLongitude) +lake(Name, Area, Depth, Elevation, Type, River, Latitude, Longitude) +riverthrough(River, Lake) +island(Name, Group, Area, Elevation, Type, Latitude, Longitude) +mountain(Name, Range, Height, Type, Latitude, Longitude) +desert(Name, Area, Longitude, Latitude, Longitude) +geo_sea(Sea, CountryCode, Province) +mergesWith(Sea1, Sea2) +located(City, Province, CountryCode, River, Lake, Sea) +islandIn(Island, Sea, Lake, River) +mountainOnIsland(Mountain, Island) +</pre> + + </body> +</html> diff --git a/prolog/problems/world_data/landlocked2_1/common.py b/prolog/problems/world_data/landlocked2_1/common.py new file mode 100644 index 0000000..3c5b3e2 --- /dev/null +++ b/prolog/problems/world_data/landlocked2_1/common.py @@ -0,0 +1,48 @@ +from operator import itemgetter +import socket +import prolog.engine +from server.hints import Hint +import server.problems + +id = 10006 +number = 60 +visible = True +facts = 'mondial' + +solution = '''\ +landlocked2(Country):- + findall(CC, (country(_,CC,_,_,_,_), \+ geo_sea(_,CC,_)), LL), + member(C, LL), + \+ ( (borders(C,C1,_) ; borders(C1,C,_)), + \+ member(C1, LL) ), + country(Country,C,_,_,_,_). +''' + +test_cases = [ + ("landlocked2(Country)", + [{'Country': "'Liechtenstein'"}, {'Country': "'Uzbekistan'"}]), + ("\+ landlocked2('Slovenia')", + [{}]), + ("landlocked2('Uzbekistan')", + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit = None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/world_data/landlocked2_1/en.py b/prolog/problems/world_data/landlocked2_1/en.py new file mode 100644 index 0000000..6d69382 --- /dev/null +++ b/prolog/problems/world_data/landlocked2_1/en.py @@ -0,0 +1,12 @@ +name = 'landlocked2/1' +slug = 'poišči države brez morja, ki ne mejijo na države z morjem' + +description = '''\ +<p>Nekatere države nimajo morja. Spet druge države imajo še manj sreče -- ne samo, da nimajo morja, +tudi ne mejijo na nobeno državo, ki bi morje imela. Po angleško takim državam rečemo "double landlocked".</p> +<p><code>landlocked2(Country)</code>: predikat eno po eno vrne vse države, ki nimajo ne morja, ne sosede +z morjem.</p> +<p>Prav ti znajo priti podatki v obliki <code>geo_sea(Sea, CountryCode, Province)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/landlocked2_1/sl.py b/prolog/problems/world_data/landlocked2_1/sl.py new file mode 100644 index 0000000..6d69382 --- /dev/null +++ b/prolog/problems/world_data/landlocked2_1/sl.py @@ -0,0 +1,12 @@ +name = 'landlocked2/1' +slug = 'poišči države brez morja, ki ne mejijo na države z morjem' + +description = '''\ +<p>Nekatere države nimajo morja. Spet druge države imajo še manj sreče -- ne samo, da nimajo morja, +tudi ne mejijo na nobeno državo, ki bi morje imela. Po angleško takim državam rečemo "double landlocked".</p> +<p><code>landlocked2(Country)</code>: predikat eno po eno vrne vse države, ki nimajo ne morja, ne sosede +z morjem.</p> +<p>Prav ti znajo priti podatki v obliki <code>geo_sea(Sea, CountryCode, Province)</code>.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/people_in_capitals_1/common.py b/prolog/problems/world_data/people_in_capitals_1/common.py new file mode 100644 index 0000000..b38a96f --- /dev/null +++ b/prolog/problems/world_data/people_in_capitals_1/common.py @@ -0,0 +1,48 @@ +from operator import itemgetter +import socket +import prolog.engine +import prolog.util +from server.hints import Hint +import server.problems + +id = 10003 +number = 30 +visible = True +facts = 'mondial' + +solution = '''\ +people_in_capitals(N) :- + findall(Pop, + (country(_,_,Capital,_,_,_), + city(Capital,_,_,Pop,_,_,_), + number(Pop)), L), + sum(L, N). +''' + +hint_type = { +} + +test_cases = [ + ('people_in_capitals(N)', [{'N': '316277426'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit=None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + if n_correct == len(test_cases): + hints += [{'id': 'final_hint'}] + return n_correct, len(test_cases), hints diff --git a/prolog/problems/world_data/people_in_capitals_1/en.py b/prolog/problems/world_data/people_in_capitals_1/en.py new file mode 100644 index 0000000..1c8b93d --- /dev/null +++ b/prolog/problems/world_data/people_in_capitals_1/en.py @@ -0,0 +1,11 @@ +name = 'people_in_capitals/1' +slug = 'number of people living in capitals' + +description = '''\ +<p><code>people_in_capitals(N)</code>: <code>N</code> is the total number of people living in capital cities of the world.</p> +<p>Useful predicates:</p> +<li><code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code></li> +<li><code>city(Name, Country ID, Province, Population, Lat, Lon, Elevation)</code>.</li> +''' + +hint = {} diff --git a/prolog/problems/world_data/people_in_capitals_1/sl.py b/prolog/problems/world_data/people_in_capitals_1/sl.py new file mode 100644 index 0000000..a72ba5e --- /dev/null +++ b/prolog/problems/world_data/people_in_capitals_1/sl.py @@ -0,0 +1,11 @@ +name = 'people_in_capitals/1' +slug = 'število prebivalcev glavnih mest' + +description = '''\ +<p><code>people_in_capitals(N)</code>: <code>N</code> je število ljudi, ki živijo v glavnih mestih po svetu.</p> +<p>Uporabni predikati:</p> +<li><code>country(Name, ID, Capital, CapitalProvince, Size, Population)</code></li> +<li><code>city(Name, Country ID, Province, Population, Lat, Lon, Elevation)</code>.</li> +''' + +hint = {} diff --git a/prolog/problems/world_data/similar_population_3/common.py b/prolog/problems/world_data/similar_population_3/common.py new file mode 100644 index 0000000..a984f1c --- /dev/null +++ b/prolog/problems/world_data/similar_population_3/common.py @@ -0,0 +1,47 @@ +from operator import itemgetter +import socket +import prolog.engine +from server.hints import Hint +import server.problems + +id = 10008 +number = 80 +visible = True +facts = 'mondial' + +solution = '''\ +simpop(X, Y, D):- + findall(D/X/Y, (country(X,_,_,_,_,PX), country(Y,_,_,_,_,PY), X \== Y, D is abs(PX-PY)), L), + sort(L, [D/X/Y|_]). +''' + +test_cases = [ + ('simpop(X, Y, D)', + [{'X': "'Grenada'", 'Y': "'Tonga'", 'D': '76'}]), + ("simpop('Slovenia', Y, D)", + [{'Y': "'Macedonia'", 'D': '973'}]), + ("simpop(X, 'Australia', D)", + [{'X': "'Taiwan'", 'D': '180541'}]), + ("simpop(X, Y, 1176831)", + [{'X': "'Uzbekistan'", 'Y': "'Venezuela'"}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit = None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/world_data/similar_population_3/en.py b/prolog/problems/world_data/similar_population_3/en.py new file mode 100644 index 0000000..e9c2516 --- /dev/null +++ b/prolog/problems/world_data/similar_population_3/en.py @@ -0,0 +1,15 @@ +name = 'simpop/3' +slug = 'countries with most similar number of residents' + +description = '''\ +<p><code>simpop(X, Y, Diff)</code>: <code>X</code> and <code>Y</code> are countries with the most similar numbers of +residents. <code>Diff</code> represents the difference between them.</p> +<pre> +?- simpop('Fiji', Y, Diff). + Y = 'Cyprus', + Diff = 20152. +</pre> +<p>Useful facts are given as <code>country(Name, ID, Capital, CapitalProvince, Size, Population).</code></p> +''' + +hint = {} diff --git a/prolog/problems/world_data/similar_population_3/sl.py b/prolog/problems/world_data/similar_population_3/sl.py new file mode 100644 index 0000000..069f35e --- /dev/null +++ b/prolog/problems/world_data/similar_population_3/sl.py @@ -0,0 +1,15 @@ +name = 'simpop/3' +slug = 'državi z najbolj podobnim številom prebivalcev' + +description = '''\ +<p><code>simpop(X, Y, Diff)</code>: <code>X</code> in <code>Y</code> je par držav z najbolj podobnim številom +prebivalcev, <code>Diff</code> je razlika med njima.</p> +<pre> +?- simpop('Fiji', Y, Diff). + Y = 'Cyprus', + Diff = 20152. +</pre> +<p>Uporabna dejstva so podana v obliki <code>country(Name, ID, Capital, CapitalProvince, Size, Population).</code></p> +''' + +hint = {} diff --git a/prolog/problems/world_data/sl.py b/prolog/problems/world_data/sl.py new file mode 100644 index 0000000..9796f98 --- /dev/null +++ b/prolog/problems/world_data/sl.py @@ -0,0 +1,10 @@ +name = 'Države sveta' +description = '''\ +<p> +Naučimo se vprašati prolog po različnih dejstvih o našem svetu, npr. skozi +katere države teče neka reka ali kateri dve državi sta si čimbolj podobni po +številu prebivalcev. Za ta namen je naložena +<a target="_blank" href="[%@resource intro_sl.html%]">baza podatkov</a> +iz almanaha svetovnih dejstev "The World Factbook". +</p> +''' diff --git a/prolog/problems/world_data/whoSpeaks_3/common.py b/prolog/problems/world_data/whoSpeaks_3/common.py new file mode 100644 index 0000000..79e4410 --- /dev/null +++ b/prolog/problems/world_data/whoSpeaks_3/common.py @@ -0,0 +1,47 @@ +from operator import itemgetter +import socket +import prolog.engine +from server.hints import Hint +import server.problems + +id = 10004 +number = 40 +visible = True +facts = 'mondial' + +solution = '''\ +whoSpeaks(Lang, Country, Num):- + language(CC, Lang, Perc), + country(Country, CC, _, _, _, Pop), + Num is Pop*Perc/100. +''' + +test_cases = [ + ("whoSpeaks('Dutch', Country, _)", + [{'Country': "'Belgium'"}, {'Country': "'Netherlands'"}, {'Country': "'Monaco'"}, + {'Country': "'Curacao'"}, {'Country': "'Sint Maarten'"}]), + ("whoSpeaks('Slovenian', 'Slovenia', Num)", + [{'Num': '1873527.11'}]), + ("\+ whoSpeaks('Italian', 'Uzbekistan', _)", + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=5.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0, inference_limit = None): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/world_data/whoSpeaks_3/en.py b/prolog/problems/world_data/whoSpeaks_3/en.py new file mode 100644 index 0000000..3dc74e6 --- /dev/null +++ b/prolog/problems/world_data/whoSpeaks_3/en.py @@ -0,0 +1,23 @@ +name = 'whoSpeaks/3' +slug = 'poišči države v katerih govorijo določen jezik' + +description = '''\ +<p>Določen jezik ne govorijo nujno samo v eni državi. Pravzaprav za večino jezikov velja, da jih govorijo +v več državah na svetu. Napiši predikat, ki ugotovi v katerih državah govorijo določen jezik in koliko je +ljudi, ki ga govorijo. Morda te rezultati presenetijo!</p> +<p><code>whoSpeaks(Lang, Country, NumOfSpeakers)</code>: predikat eno po eno vrne vse države <code>Country</code> +v kateri govorijo jezik <code>Lang</code> in obenem vrne tudi koliko ljudi </code>NumOfSpeakers</code> v tej državi +govori ta jezik.</p> +<pre> +?- whoSpeaks('Spanish', Country, NumOfSpeakers). + Country = 'Spain', NumOfSpeakers = 34643777 ; + Country = 'Andorra', NumOfSpeakers = 25777 ; + Country = 'Belize', NumOfSpeakers = 143966 ; + ... +</pre> +<p>Prav ti znajo priti podatki v obliki <code>language(CountryCode, Language, PercentageOfSpeakers)</code>.</p> +<p>S pomočjo napisanega predikata lahko hitro ugotoviš v koliko državah govorijo nek jezik ali v kateri državi je +najbolj pogost. Lahko poskusiš postaviti ustrezno vprašanje prologu v konzoli.</p> +''' + +hint = {} diff --git a/prolog/problems/world_data/whoSpeaks_3/sl.py b/prolog/problems/world_data/whoSpeaks_3/sl.py new file mode 100644 index 0000000..3dc74e6 --- /dev/null +++ b/prolog/problems/world_data/whoSpeaks_3/sl.py @@ -0,0 +1,23 @@ +name = 'whoSpeaks/3' +slug = 'poišči države v katerih govorijo določen jezik' + +description = '''\ +<p>Določen jezik ne govorijo nujno samo v eni državi. Pravzaprav za večino jezikov velja, da jih govorijo +v več državah na svetu. Napiši predikat, ki ugotovi v katerih državah govorijo določen jezik in koliko je +ljudi, ki ga govorijo. Morda te rezultati presenetijo!</p> +<p><code>whoSpeaks(Lang, Country, NumOfSpeakers)</code>: predikat eno po eno vrne vse države <code>Country</code> +v kateri govorijo jezik <code>Lang</code> in obenem vrne tudi koliko ljudi </code>NumOfSpeakers</code> v tej državi +govori ta jezik.</p> +<pre> +?- whoSpeaks('Spanish', Country, NumOfSpeakers). + Country = 'Spain', NumOfSpeakers = 34643777 ; + Country = 'Andorra', NumOfSpeakers = 25777 ; + Country = 'Belize', NumOfSpeakers = 143966 ; + ... +</pre> +<p>Prav ti znajo priti podatki v obliki <code>language(CountryCode, Language, PercentageOfSpeakers)</code>.</p> +<p>S pomočjo napisanega predikata lahko hitro ugotoviš v koliko državah govorijo nek jezik ali v kateri državi je +najbolj pogost. Lahko poskusiš postaviti ustrezno vprašanje prologu v konzoli.</p> +''' + +hint = {} |