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/world_data/whoSpeaks_3 | |
parent | 0bfa95be7046b101a00f83f082260b5d0e007159 (diff) | |
parent | 9d662ae9b7a84b3826e91d2af17f251daaabcd79 (diff) |
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'prolog/problems/world_data/whoSpeaks_3')
-rw-r--r-- | prolog/problems/world_data/whoSpeaks_3/common.py | 47 | ||||
-rw-r--r-- | prolog/problems/world_data/whoSpeaks_3/en.py | 23 | ||||
-rw-r--r-- | prolog/problems/world_data/whoSpeaks_3/sl.py | 23 |
3 files changed, 93 insertions, 0 deletions
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 = {} |