From 72a899429bd5c219c718665c037a5e46ad143ed2 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Mon, 6 Mar 2017 19:55:07 +0100 Subject: World Data exercises updated. --- .../problems/world_data/similar_population_3/common.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 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): -- cgit v1.2.1