summaryrefslogtreecommitdiff
path: root/prolog/problems/world_data/whoSpeaks_3
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-10-18 16:20:10 +0200
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-10-18 16:20:10 +0200
commit64e1f9eb2e18910e4ecc7299c53868445d3ed9b1 (patch)
treea8213930b1295490ab6dd541722870287f29c293 /prolog/problems/world_data/whoSpeaks_3
parent6a5d6fc44906734b35f5fcb70a447c5300bf26e5 (diff)
Week2: whoSpeaks/3 exercises added.
Diffstat (limited to 'prolog/problems/world_data/whoSpeaks_3')
-rw-r--r--prolog/problems/world_data/whoSpeaks_3/common.py47
-rw-r--r--prolog/problems/world_data/whoSpeaks_3/en.py23
-rw-r--r--prolog/problems/world_data/whoSpeaks_3/sl.py23
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..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 = '''\
+<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 = {}