From c5139404dff6f3266489e8b041ee6b92b8a03538 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 17 Oct 2016 16:19:23 +0200 Subject: Week2: simpop/3 exercise added. --- .../world_data/similar_population_3/common.py | 47 ++++++++++++++++++++++ .../problems/world_data/similar_population_3/en.py | 15 +++++++ .../problems/world_data/similar_population_3/sl.py | 15 +++++++ 3 files changed, 77 insertions(+) create mode 100644 prolog/problems/world_data/similar_population_3/common.py create mode 100644 prolog/problems/world_data/similar_population_3/en.py create mode 100644 prolog/problems/world_data/similar_population_3/sl.py (limited to 'prolog/problems/world_data/similar_population_3') 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..11d541b --- /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 = 12519 +number = 1 +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 = '''\ +

simpop(X, Y, Diff): X and Y are countries with the most similar numbers of +residents. Diff represents the difference between them.

+
+?- simpop('Fiji', Y, Diff).
+  Y = 'Cyprus',
+  Diff = 20152.
+
+

Useful facts are given as country(Name, ID, Capital, CapitalProvince, Size, Population).

+''' + +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 = '''\ +

simpop(X, Y, Diff): X in Y je par držav z najbolj podobnim številom +prebivalcev, Diff je razlika med njima.

+
+?- simpop('Fiji', Y, Diff).
+  Y = 'Cyprus',
+  Diff = 20152.
+
+

Uporabna dejstva so podana v obliki country(Name, ID, Capital, CapitalProvince, Size, Population).

+''' + +hint = {} -- cgit v1.2.1 From edf712f8b4a6a3e73d3cca9b5173ed270a3c634b Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 17 Oct 2016 22:56:32 +0200 Subject: Week2: holiday/2 exercise added. --- prolog/problems/world_data/similar_population_3/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'prolog/problems/world_data/similar_population_3') diff --git a/prolog/problems/world_data/similar_population_3/common.py b/prolog/problems/world_data/similar_population_3/common.py index 11d541b..2226a30 100644 --- a/prolog/problems/world_data/similar_population_3/common.py +++ b/prolog/problems/world_data/similar_population_3/common.py @@ -5,7 +5,7 @@ from server.hints import Hint import server.problems id = 12519 -number = 1 +number = 40 visible = True facts = 'mondial' -- cgit v1.2.1 From 08cc8882bf1a1d77c192726954883bfd5bff7a5a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 18 Oct 2016 16:26:31 +0200 Subject: Prolog: fix world_data problem IDs and numbers --- prolog/problems/world_data/similar_population_3/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prolog/problems/world_data/similar_population_3') diff --git a/prolog/problems/world_data/similar_population_3/common.py b/prolog/problems/world_data/similar_population_3/common.py index 2226a30..a984f1c 100644 --- a/prolog/problems/world_data/similar_population_3/common.py +++ b/prolog/problems/world_data/similar_population_3/common.py @@ -4,8 +4,8 @@ import prolog.engine from server.hints import Hint import server.problems -id = 12519 -number = 40 +id = 10008 +number = 80 visible = True facts = 'mondial' -- cgit v1.2.1