summaryrefslogtreecommitdiff
path: root/prolog/problems/world_data/similar_population_3
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2017-03-06 19:55:07 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2017-03-06 19:55:07 +0100
commit72a899429bd5c219c718665c037a5e46ad143ed2 (patch)
treeea00875178ab8913c791246c31542f1b8cf6bd68 /prolog/problems/world_data/similar_population_3
parent789ac4a72a7400d4463cd479bd222516009c3538 (diff)
World Data exercises updated.
Diffstat (limited to 'prolog/problems/world_data/similar_population_3')
-rw-r--r--prolog/problems/world_data/similar_population_3/common.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/prolog/problems/world_data/similar_population_3/common.py b/prolog/problems/world_data/similar_population_3/common.py
index a984f1c..b8a391c 100644
--- a/prolog/problems/world_data/similar_population_3/common.py
+++ b/prolog/problems/world_data/similar_population_3/common.py
@@ -11,19 +11,22 @@ 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|_]).
+ country(X,_,_,_,_,PX),
+ country(Y,_,_,_,_,PY),
+ X \== Y,
+ D is abs(PX-PY),
+ \+ (country(Z,_,_,_,_,PZ), Z \== X, D > abs(PX-PZ)).
'''
test_cases = [
- ('simpop(X, Y, D)',
- [{'X': "'Grenada'", 'Y': "'Tonga'", 'D': '76'}]),
+ ("simpop('Tonga', Y, D)",
+ [{'Y': "'Grenada'", 'D': '76'}]),
("simpop('Slovenia', Y, D)",
[{'Y': "'Macedonia'", 'D': '973'}]),
- ("simpop(X, 'Australia', D)",
- [{'X': "'Taiwan'", 'D': '180541'}]),
+ ("simpop(X, 'Slovenia', D)",
+ [{'X': "'Macedonia'", 'D': '973'}, {'X': "'Botswana'", 'D': '20593'}]),
("simpop(X, Y, 1176831)",
- [{'X': "'Uzbekistan'", 'Y': "'Venezuela'"}]),
+ [{'Y': "'Uzbekistan'", 'X': "'Venezuela'"}]),
]
def test(code, aux_code):