From 64e1f9eb2e18910e4ecc7299c53868445d3ed9b1 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Tue, 18 Oct 2016 16:20:10 +0200 Subject: Week2: whoSpeaks/3 exercises added. --- prolog/problems/world_data/whoSpeaks_3/common.py | 47 ++++++++++++++++++++++++ prolog/problems/world_data/whoSpeaks_3/en.py | 23 ++++++++++++ prolog/problems/world_data/whoSpeaks_3/sl.py | 23 ++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 prolog/problems/world_data/whoSpeaks_3/common.py create mode 100644 prolog/problems/world_data/whoSpeaks_3/en.py create mode 100644 prolog/problems/world_data/whoSpeaks_3/sl.py (limited to 'prolog/problems/world_data/whoSpeaks_3') 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..b80e5d5 --- /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 = 12549 +number = 369 +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 = '''\ +

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!

+

whoSpeaks(Lang, Country, NumOfSpeakers): predikat eno po eno vrne vse države Country +v kateri govorijo jezik Lang in obenem vrne tudi koliko ljudi NumOfSpeakers v tej državi +govori ta jezik.

+
+?- whoSpeaks('Spanish', Country, NumOfSpeakers).
+  Country = 'Spain', NumOfSpeakers = 34643777 ;
+  Country = 'Andorra', NumOfSpeakers = 25777 ;
+  Country = 'Belize', NumOfSpeakers = 143966 ;
+  ...
+
+

Prav ti znajo priti podatki v obliki language(CountryCode, Language, PercentageOfSpeakers).

+

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.

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

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!

+

whoSpeaks(Lang, Country, NumOfSpeakers): predikat eno po eno vrne vse države Country +v kateri govorijo jezik Lang in obenem vrne tudi koliko ljudi NumOfSpeakers v tej državi +govori ta jezik.

+
+?- whoSpeaks('Spanish', Country, NumOfSpeakers).
+  Country = 'Spain', NumOfSpeakers = 34643777 ;
+  Country = 'Andorra', NumOfSpeakers = 25777 ;
+  Country = 'Belize', NumOfSpeakers = 143966 ;
+  ...
+
+

Prav ti znajo priti podatki v obliki language(CountryCode, Language, PercentageOfSpeakers).

+

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.

+''' + +hint = {} -- cgit v1.2.1 From f4216395fcf2fec2f512d0c88f53021dfda6ad7b Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 18 Oct 2016 16:28:43 +0200 Subject: Prolog: change ID and number for whoSpeaks_3 --- prolog/problems/world_data/whoSpeaks_3/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'prolog/problems/world_data/whoSpeaks_3') diff --git a/prolog/problems/world_data/whoSpeaks_3/common.py b/prolog/problems/world_data/whoSpeaks_3/common.py index b80e5d5..79e4410 100644 --- a/prolog/problems/world_data/whoSpeaks_3/common.py +++ b/prolog/problems/world_data/whoSpeaks_3/common.py @@ -4,8 +4,8 @@ import prolog.engine from server.hints import Hint import server.problems -id = 12549 -number = 369 +id = 10004 +number = 40 visible = True facts = 'mondial' -- cgit v1.2.1