diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-10-18 02:11:35 +0200 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-10-18 02:11:35 +0200 |
commit | 6a5d6fc44906734b35f5fcb70a447c5300bf26e5 (patch) | |
tree | 0daf3071c134a33a201f0ec27eb385c9681e216d /prolog/problems | |
parent | edf712f8b4a6a3e73d3cca9b5173ed270a3c634b (diff) |
Week2: grant/1 and landlocked2/1 exercises added.
Diffstat (limited to 'prolog/problems')
-rw-r--r-- | prolog/problems/world_data/grant_1/common.py | 50 | ||||
-rw-r--r-- | prolog/problems/world_data/grant_1/en.py | 15 | ||||
-rw-r--r-- | prolog/problems/world_data/grant_1/sl.py | 15 | ||||
-rw-r--r-- | prolog/problems/world_data/landlocked2_1/common.py | 48 | ||||
-rw-r--r-- | prolog/problems/world_data/landlocked2_1/en.py | 12 | ||||
-rw-r--r-- | prolog/problems/world_data/landlocked2_1/sl.py | 12 |
6 files changed, 152 insertions, 0 deletions
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..aa016b0 --- /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 = 12536 +number = 20 +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/landlocked2_1/common.py b/prolog/problems/world_data/landlocked2_1/common.py new file mode 100644 index 0000000..5c17886 --- /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 = 12539 +number = 39 +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 = {} |