From cf4e59c9d6bce337514fc7d77120baced0d6d7bc Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 17 Mar 2016 14:19:45 +0100 Subject: Prolog: split lists exercises into two groups --- prolog/problems/clp_fd/common.py | 2 +- prolog/problems/clp_r/common.py | 2 +- prolog/problems/dcg/common.py | 2 +- prolog/problems/denotational_semantics/common.py | 2 +- prolog/problems/license_plates/common.py | 2 +- prolog/problems/lists/count_3/common.py | 54 --------------------- prolog/problems/lists/count_3/en.py | 13 ----- prolog/problems/lists/count_3/sl.py | 13 ----- .../problems/lists/evenlen_1_+_oddlen_1/common.py | 56 ---------------------- prolog/problems/lists/evenlen_1_+_oddlen_1/en.py | 18 ------- prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py | 18 ------- prolog/problems/lists/len_2/common.py | 49 ------------------- prolog/problems/lists/len_2/en.py | 13 ----- prolog/problems/lists/len_2/sl.py | 13 ----- prolog/problems/lists/max_2/common.py | 53 -------------------- prolog/problems/lists/max_2/en.py | 15 ------ prolog/problems/lists/max_2/sl.py | 15 ------ prolog/problems/lists/min_2/common.py | 53 -------------------- prolog/problems/lists/min_2/en.py | 15 ------ prolog/problems/lists/min_2/sl.py | 15 ------ prolog/problems/lists/palindrome_1/common.py | 54 --------------------- prolog/problems/lists/palindrome_1/en.py | 15 ------ prolog/problems/lists/palindrome_1/sl.py | 15 ------ prolog/problems/lists/rev_2/common.py | 52 -------------------- prolog/problems/lists/rev_2/en.py | 15 ------ prolog/problems/lists/rev_2/sl.py | 15 ------ prolog/problems/lists/shiftleft_2/common.py | 50 ------------------- prolog/problems/lists/shiftleft_2/en.py | 13 ----- prolog/problems/lists/shiftleft_2/sl.py | 13 ----- prolog/problems/lists/shiftright_2/common.py | 50 ------------------- prolog/problems/lists/shiftright_2/en.py | 13 ----- prolog/problems/lists/shiftright_2/sl.py | 13 ----- prolog/problems/lists/sl.py | 1 - prolog/problems/lists/sublist_2/common.py | 53 -------------------- prolog/problems/lists/sublist_2/en.py | 19 -------- prolog/problems/lists/sublist_2/sl.py | 19 -------- prolog/problems/lists/sum_2/common.py | 49 ------------------- prolog/problems/lists/sum_2/en.py | 13 ----- prolog/problems/lists/sum_2/sl.py | 13 ----- prolog/problems/lists_advanced/common.py | 2 + prolog/problems/lists_advanced/count_3/common.py | 54 +++++++++++++++++++++ prolog/problems/lists_advanced/count_3/en.py | 13 +++++ prolog/problems/lists_advanced/count_3/sl.py | 13 +++++ prolog/problems/lists_advanced/en.py | 5 ++ .../lists_advanced/evenlen_1_+_oddlen_1/common.py | 56 ++++++++++++++++++++++ .../lists_advanced/evenlen_1_+_oddlen_1/en.py | 18 +++++++ .../lists_advanced/evenlen_1_+_oddlen_1/sl.py | 18 +++++++ prolog/problems/lists_advanced/len_2/common.py | 49 +++++++++++++++++++ prolog/problems/lists_advanced/len_2/en.py | 13 +++++ prolog/problems/lists_advanced/len_2/sl.py | 13 +++++ prolog/problems/lists_advanced/max_2/common.py | 53 ++++++++++++++++++++ prolog/problems/lists_advanced/max_2/en.py | 15 ++++++ prolog/problems/lists_advanced/max_2/sl.py | 15 ++++++ prolog/problems/lists_advanced/min_2/common.py | 53 ++++++++++++++++++++ prolog/problems/lists_advanced/min_2/en.py | 15 ++++++ prolog/problems/lists_advanced/min_2/sl.py | 15 ++++++ .../problems/lists_advanced/palindrome_1/common.py | 54 +++++++++++++++++++++ prolog/problems/lists_advanced/palindrome_1/en.py | 15 ++++++ prolog/problems/lists_advanced/palindrome_1/sl.py | 15 ++++++ prolog/problems/lists_advanced/rev_2/common.py | 52 ++++++++++++++++++++ prolog/problems/lists_advanced/rev_2/en.py | 15 ++++++ prolog/problems/lists_advanced/rev_2/sl.py | 15 ++++++ .../problems/lists_advanced/shiftleft_2/common.py | 50 +++++++++++++++++++ prolog/problems/lists_advanced/shiftleft_2/en.py | 13 +++++ prolog/problems/lists_advanced/shiftleft_2/sl.py | 13 +++++ .../problems/lists_advanced/shiftright_2/common.py | 50 +++++++++++++++++++ prolog/problems/lists_advanced/shiftright_2/en.py | 13 +++++ prolog/problems/lists_advanced/shiftright_2/sl.py | 13 +++++ prolog/problems/lists_advanced/sl.py | 5 ++ prolog/problems/lists_advanced/sublist_2/common.py | 53 ++++++++++++++++++++ prolog/problems/lists_advanced/sublist_2/en.py | 19 ++++++++ prolog/problems/lists_advanced/sublist_2/sl.py | 19 ++++++++ prolog/problems/lists_advanced/sum_2/common.py | 49 +++++++++++++++++++ prolog/problems/lists_advanced/sum_2/en.py | 13 +++++ prolog/problems/lists_advanced/sum_2/sl.py | 13 +++++ prolog/problems/sets/common.py | 2 +- prolog/problems/sorting/common.py | 2 +- prolog/problems/trees/common.py | 2 +- readme.md | 6 +++ 79 files changed, 923 insertions(+), 906 deletions(-) delete mode 100644 prolog/problems/lists/count_3/common.py delete mode 100644 prolog/problems/lists/count_3/en.py delete mode 100644 prolog/problems/lists/count_3/sl.py delete mode 100644 prolog/problems/lists/evenlen_1_+_oddlen_1/common.py delete mode 100644 prolog/problems/lists/evenlen_1_+_oddlen_1/en.py delete mode 100644 prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py delete mode 100644 prolog/problems/lists/len_2/common.py delete mode 100644 prolog/problems/lists/len_2/en.py delete mode 100644 prolog/problems/lists/len_2/sl.py delete mode 100644 prolog/problems/lists/max_2/common.py delete mode 100644 prolog/problems/lists/max_2/en.py delete mode 100644 prolog/problems/lists/max_2/sl.py delete mode 100644 prolog/problems/lists/min_2/common.py delete mode 100644 prolog/problems/lists/min_2/en.py delete mode 100644 prolog/problems/lists/min_2/sl.py delete mode 100644 prolog/problems/lists/palindrome_1/common.py delete mode 100644 prolog/problems/lists/palindrome_1/en.py delete mode 100644 prolog/problems/lists/palindrome_1/sl.py delete mode 100644 prolog/problems/lists/rev_2/common.py delete mode 100644 prolog/problems/lists/rev_2/en.py delete mode 100644 prolog/problems/lists/rev_2/sl.py delete mode 100644 prolog/problems/lists/shiftleft_2/common.py delete mode 100644 prolog/problems/lists/shiftleft_2/en.py delete mode 100644 prolog/problems/lists/shiftleft_2/sl.py delete mode 100644 prolog/problems/lists/shiftright_2/common.py delete mode 100644 prolog/problems/lists/shiftright_2/en.py delete mode 100644 prolog/problems/lists/shiftright_2/sl.py delete mode 100644 prolog/problems/lists/sublist_2/common.py delete mode 100644 prolog/problems/lists/sublist_2/en.py delete mode 100644 prolog/problems/lists/sublist_2/sl.py delete mode 100644 prolog/problems/lists/sum_2/common.py delete mode 100644 prolog/problems/lists/sum_2/en.py delete mode 100644 prolog/problems/lists/sum_2/sl.py create mode 100644 prolog/problems/lists_advanced/common.py create mode 100644 prolog/problems/lists_advanced/count_3/common.py create mode 100644 prolog/problems/lists_advanced/count_3/en.py create mode 100644 prolog/problems/lists_advanced/count_3/sl.py create mode 100644 prolog/problems/lists_advanced/en.py create mode 100644 prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py create mode 100644 prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py create mode 100644 prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py create mode 100644 prolog/problems/lists_advanced/len_2/common.py create mode 100644 prolog/problems/lists_advanced/len_2/en.py create mode 100644 prolog/problems/lists_advanced/len_2/sl.py create mode 100644 prolog/problems/lists_advanced/max_2/common.py create mode 100644 prolog/problems/lists_advanced/max_2/en.py create mode 100644 prolog/problems/lists_advanced/max_2/sl.py create mode 100644 prolog/problems/lists_advanced/min_2/common.py create mode 100644 prolog/problems/lists_advanced/min_2/en.py create mode 100644 prolog/problems/lists_advanced/min_2/sl.py create mode 100644 prolog/problems/lists_advanced/palindrome_1/common.py create mode 100644 prolog/problems/lists_advanced/palindrome_1/en.py create mode 100644 prolog/problems/lists_advanced/palindrome_1/sl.py create mode 100644 prolog/problems/lists_advanced/rev_2/common.py create mode 100644 prolog/problems/lists_advanced/rev_2/en.py create mode 100644 prolog/problems/lists_advanced/rev_2/sl.py create mode 100644 prolog/problems/lists_advanced/shiftleft_2/common.py create mode 100644 prolog/problems/lists_advanced/shiftleft_2/en.py create mode 100644 prolog/problems/lists_advanced/shiftleft_2/sl.py create mode 100644 prolog/problems/lists_advanced/shiftright_2/common.py create mode 100644 prolog/problems/lists_advanced/shiftright_2/en.py create mode 100644 prolog/problems/lists_advanced/shiftright_2/sl.py create mode 100644 prolog/problems/lists_advanced/sl.py create mode 100644 prolog/problems/lists_advanced/sublist_2/common.py create mode 100644 prolog/problems/lists_advanced/sublist_2/en.py create mode 100644 prolog/problems/lists_advanced/sublist_2/sl.py create mode 100644 prolog/problems/lists_advanced/sum_2/common.py create mode 100644 prolog/problems/lists_advanced/sum_2/en.py create mode 100644 prolog/problems/lists_advanced/sum_2/sl.py diff --git a/prolog/problems/clp_fd/common.py b/prolog/problems/clp_fd/common.py index 3b1f9cf..f62433e 100644 --- a/prolog/problems/clp_fd/common.py +++ b/prolog/problems/clp_fd/common.py @@ -1,2 +1,2 @@ id = 8 -number = 7 +number = 8 diff --git a/prolog/problems/clp_r/common.py b/prolog/problems/clp_r/common.py index 2238250..7f45af1 100644 --- a/prolog/problems/clp_r/common.py +++ b/prolog/problems/clp_r/common.py @@ -1,2 +1,2 @@ id = 9 -number = 8 +number = 9 diff --git a/prolog/problems/dcg/common.py b/prolog/problems/dcg/common.py index 4992f2d..a55cdef 100644 --- a/prolog/problems/dcg/common.py +++ b/prolog/problems/dcg/common.py @@ -1,2 +1,2 @@ id = 10 -number = 9 +number = 10 diff --git a/prolog/problems/denotational_semantics/common.py b/prolog/problems/denotational_semantics/common.py index e2c420e..86c7532 100644 --- a/prolog/problems/denotational_semantics/common.py +++ b/prolog/problems/denotational_semantics/common.py @@ -1,2 +1,2 @@ id = 11 -number = 10 +number = 11 diff --git a/prolog/problems/license_plates/common.py b/prolog/problems/license_plates/common.py index 3d15487..e35a349 100644 --- a/prolog/problems/license_plates/common.py +++ b/prolog/problems/license_plates/common.py @@ -1,2 +1,2 @@ id = 7 -number = 6 +number = 7 diff --git a/prolog/problems/lists/count_3/common.py b/prolog/problems/lists/count_3/common.py deleted file mode 100644 index 2953f06..0000000 --- a/prolog/problems/lists/count_3/common.py +++ /dev/null @@ -1,54 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 120 -number = 27 -visible = False -facts = None - -solution = '''\ -count(_, [], 0). -count(X, [X|T], N) :- - count(X, T, NT), - N is NT + 1. -count(X, [Y|T], NT) :- - X \== Y, - count(X, T, NT). -''' - -test_cases = [ - ('count(a, [], X)', - [{'X': '0'}]), - ('count(r, [a, r, b, c, r], X)', - [{'X': '2'}]), - ('count(l, [l, l, l, 1, 2, 3], X)', - [{'X': '3'}]), - ('count(z, [a, b, c, z, z], X)', - [{'X': '2'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/count_3/en.py b/prolog/problems/lists/count_3/en.py deleted file mode 100644 index dd13bc0..0000000 --- a/prolog/problems/lists/count_3/en.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'count/3' -slug = 'find the number of occurrences of an element in list' - -description = '''\ -

count(X, L, N): N is the number of times the element X appears in the list L.

-
-?- count(1, [1,2,1,3,1], N).
-  N = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/count_3/sl.py b/prolog/problems/lists/count_3/sl.py deleted file mode 100644 index 98cd6f8..0000000 --- a/prolog/problems/lists/count_3/sl.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'count/3' -slug = 'Preštej kolikokrat se element pojavi v seznamu' - -description = '''\ -

count(X, L, N): N je število kolikokrat se element X pojavi v seznamu L.

-
-?- count(1, [1,2,1,3,1], N).
-  N = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py deleted file mode 100644 index 1236551..0000000 --- a/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py +++ /dev/null @@ -1,56 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 116 -number = 23 -visible = False -facts = None - -solution = '''\ -evenlen([]). -evenlen([_,_|T]) :- - evenlen(T). - -oddlen([_]). -oddlen([_,_|T]) :- - oddlen(T). -''' - -test_cases = [ - ('evenlen([])', - [{}]), - ('evenlen([r, w, t, q])', - [{}]), - ('\+ evenlen([r, w, t, q, l])', - [{}]), - ('\+ oddlen([r, w, t, q])', - [{}]), - ('oddlen([r, w, t, q, l])', - [{}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py deleted file mode 100644 index a01a41b..0000000 --- a/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py +++ /dev/null @@ -1,18 +0,0 @@ -# coding=utf-8 - -name = 'evenlen/1 + oddlen/1' -slug = 'check if the length of a list is even or odd' - -description = '''\ -

evenlen(L): the list L has an even number of elements.
-oddlen(L): the list L has an odd number of elements.

-
-?- oddlen([1,2,3,4,5]).
-  true.
-?- oddlen([1,2,3,4]).
-  false.
-?- evenlen([1,2,3,4]).
-  true.
-
''' - -hint = {} diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py deleted file mode 100644 index 4ca44c2..0000000 --- a/prolog/problems/lists/evenlen_1_+_oddlen_1/sl.py +++ /dev/null @@ -1,18 +0,0 @@ -# coding=utf-8 - -name = 'evenlen/1 + oddlen/1' -slug = 'Brez aritmetike preveri, če je seznam sode ali lihe dolžine' - -description = '''\ -

evenlen(L): seznam L ima sodo število elementov.
-oddlen(L): seznam L ima liho število elementov.

-
-?- oddlen([1,2,3,4,5]).
-  true.
-?- oddlen([1,2,3,4]).
-  false.
-?- evenlen([1,2,3,4]).
-  true.
-
''' - -hint = {} diff --git a/prolog/problems/lists/len_2/common.py b/prolog/problems/lists/len_2/common.py deleted file mode 100644 index 93a1faa..0000000 --- a/prolog/problems/lists/len_2/common.py +++ /dev/null @@ -1,49 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 119 -number = 26 -visible = False -facts = None - -solution = '''\ -len([], 0). -len([_|T], Len) :- - len(T, LenT), - Len is LenT + 1. -''' - -test_cases = [ - ('len([8, 3, 5, 1], X)', - [{'X': '4'}]), - ('len([2, -3, 5, 0, 3], X)', - [{'X': '5'}]), - ('len([], X)', - [{'X': '0'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/len_2/en.py b/prolog/problems/lists/len_2/en.py deleted file mode 100644 index 3ca963e..0000000 --- a/prolog/problems/lists/len_2/en.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'len/2' -slug = 'find the length of a list' - -description = '''\ -

len(L, Len): Len is the length of the list L.

-
-?- len([1,2,3], Len).
-  Len = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/len_2/sl.py b/prolog/problems/lists/len_2/sl.py deleted file mode 100644 index 0e98272..0000000 --- a/prolog/problems/lists/len_2/sl.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'len/2' -slug = 'Izračunaj dolžino danega seznama' - -description = '''\ -

len(L, Len): Len je dolžina seznama L.

-
-?- len([1,2,3], Len).
-  Len = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/max_2/common.py b/prolog/problems/lists/max_2/common.py deleted file mode 100644 index 92cf793..0000000 --- a/prolog/problems/lists/max_2/common.py +++ /dev/null @@ -1,53 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 109 -number = 16 -visible = False -facts = None - -solution = '''\ -max([X], X). -max([H|T], Max):- - max(T, Max1), - ( H > Max1, Max is H - ; - H =< Max1, Max is Max1 ). -''' - -test_cases = [ - ('max([15], X)', - [{'X': '15'}]), - ('max([22, 13, 81], X)', - [{'X': '81'}]), - ('max([42, 42, 42, 42], X)', - [{'X': '42'}]), - ('max([-22, -113, -41], X)', - [{'X': '-22'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/max_2/en.py b/prolog/problems/lists/max_2/en.py deleted file mode 100644 index c4bc7e2..0000000 --- a/prolog/problems/lists/max_2/en.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'max/2' -slug = 'find the largest element in list' - -description = '''\ -

max(L, Max): Max is the largest value in the list L.

-
-?- max([5,4,1,6], M).
-  M = 6.
-?- max([3,2,2], M).
-  M = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/max_2/sl.py b/prolog/problems/lists/max_2/sl.py deleted file mode 100644 index 7a0d07a..0000000 --- a/prolog/problems/lists/max_2/sl.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'max/2' -slug = 'Poišči največji element v danem seznamu' - -description = '''\ -

max(L, Max): Max je največji element v seznamu L.

-
-?- max([5,4,1,6], M).
-  M = 6.
-?- max([3,2,2], M).
-  M = 3.
-
''' - -hint = {} diff --git a/prolog/problems/lists/min_2/common.py b/prolog/problems/lists/min_2/common.py deleted file mode 100644 index 213da5a..0000000 --- a/prolog/problems/lists/min_2/common.py +++ /dev/null @@ -1,53 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 108 -number = 15 -visible = False -facts = None - -solution = '''\ -min([X], X). -min([H|T], Min):- - min(T, Min1), - ( H < Min1, Min is H - ; - H >= Min1, Min is Min1 ). -''' - -test_cases = [ - ('min([15], X)', - [{'X': '15'}]), - ('min([22, 13, 81], X)', - [{'X': '13'}]), - ('min([42, 42, 42, 42], X)', - [{'X': '42'}]), - ('min([-22, 113, 1], X)', - [{'X': '-22'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/min_2/en.py b/prolog/problems/lists/min_2/en.py deleted file mode 100644 index 18f45a6..0000000 --- a/prolog/problems/lists/min_2/en.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'min/2' -slug = 'find the smallest element' - -description = '''\ -

min(L, Min): Min is the smallest value in the list L.

-
-?- min([5,4,1,6], M).
-  M = 1.
-?- min([3,2,2], M).
-  M = 2.
-
''' - -hint = {} diff --git a/prolog/problems/lists/min_2/sl.py b/prolog/problems/lists/min_2/sl.py deleted file mode 100644 index 703a05e..0000000 --- a/prolog/problems/lists/min_2/sl.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'min/2' -slug = 'Poišči najmanjši element v danem seznamu' - -description = '''\ -

min(L, Min): Min je najmanjši element v seznamu L.

-
-?- min([5,4,1,6], M).
-  M = 1.
-?- min([3,2,2], M).
-  M = 2.
-
''' - -hint = {} diff --git a/prolog/problems/lists/palindrome_1/common.py b/prolog/problems/lists/palindrome_1/common.py deleted file mode 100644 index e9960c6..0000000 --- a/prolog/problems/lists/palindrome_1/common.py +++ /dev/null @@ -1,54 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 112 -number = 19 -visible = False -facts = None - -solution = '''\ -conc112([], L, L). -conc112([H|T], L2, [H|L]) :- - conc112(T, L2, L). -rev112([], []). -rev112([H|T], R):- - rev112(T, R1), - conc112(R1, [H], R). -palindrome(L) :- - rev112(L, L). -''' - -test_cases = [ - ('palindrome([])', - [{}]), - ('palindrome([a, b, e, A, B, C])', - [{'A': 'e', 'B': 'b', 'C': 'a'}]), - ('palindrome([b, e, X])', - [{'X': 'b'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/palindrome_1/en.py b/prolog/problems/lists/palindrome_1/en.py deleted file mode 100644 index 48ee8ac..0000000 --- a/prolog/problems/lists/palindrome_1/en.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'palindrome/1' -slug = 'check if list is a palindrome' - -description = '''\ -

palindrome(L): the elements of list L are the same when read from the front or back of the list.

-
-?- palindrome([1,2,3,2,1]).
-  true.
-?- palindrome([1,2,3]).
-  false.
-
''' - -hint = {} diff --git a/prolog/problems/lists/palindrome_1/sl.py b/prolog/problems/lists/palindrome_1/sl.py deleted file mode 100644 index ad67d3f..0000000 --- a/prolog/problems/lists/palindrome_1/sl.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'palindrome/1' -slug = 'Preveri, če elementi seznama tvorijo palindrom' - -description = '''\ -

palindrome(L): Elementi seznama L se preberejo v istem vrstnem redu z začetka in s konca seznama.

-
-?- palindrome([1,2,3,2,1]).
-  true.
-?- palindrome([1,2,3]).
-  false.
-
''' - -hint = {} diff --git a/prolog/problems/lists/rev_2/common.py b/prolog/problems/lists/rev_2/common.py deleted file mode 100644 index 408389a..0000000 --- a/prolog/problems/lists/rev_2/common.py +++ /dev/null @@ -1,52 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 111 -number = 18 -visible = False -facts = None - -solution = '''\ -conc111([], L, L). -conc111([H|T], L2, [H|L]) :- - conc111(T, L2, L). -rev([], []). -rev([H|T], R):- - rev(T, R1), - conc111(R1, [H], R). -''' - -test_cases = [ - ('rev([], X)', - [{'X': '[]'}]), - ('rev([s, k, c, d, d], X)', - [{'X': '[d, d, c, k, s]'}]), - ('rev(X, [s, k, c, d, d])', - [{'X': '[d, d, c, k, s]'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/rev_2/en.py b/prolog/problems/lists/rev_2/en.py deleted file mode 100644 index 3ae126e..0000000 --- a/prolog/problems/lists/rev_2/en.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'rev/2' -slug = 'reverse a list' - -description = '''\ -

rev(L1, L2): the list L2 is obtained from L1 by reversing the order of the elements.

-
-?- rev([1,2,3], X).
-  X = [3,2,1].
-?- rev([], X).
-  X = [].
-
''' - -hint = {} diff --git a/prolog/problems/lists/rev_2/sl.py b/prolog/problems/lists/rev_2/sl.py deleted file mode 100644 index ab58a1c..0000000 --- a/prolog/problems/lists/rev_2/sl.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 - -name = 'rev/2' -slug = 'Obrni seznam' - -description = '''\ -

rev(L1, L2): seznam L2 ima elemente v obratnem vrstnem redu kot seznam L1.

-
-?- rev([1,2,3], X).
-  X = [3,2,1].
-?- rev([], X).
-  X = [].
-
''' - -hint = {} diff --git a/prolog/problems/lists/shiftleft_2/common.py b/prolog/problems/lists/shiftleft_2/common.py deleted file mode 100644 index 13db28f..0000000 --- a/prolog/problems/lists/shiftleft_2/common.py +++ /dev/null @@ -1,50 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 113 -number = 20 -visible = False -facts = None - -solution = '''\ -conc113([], L, L). -conc113([H|T], L2, [H|L]) :- - conc113(T, L2, L). -shiftleft([H|T], L2) :- - conc113(T, [H], L2). -''' - -test_cases = [ - ('shiftleft([i], X)', - [{'X': '[i]'}]), - ('shiftleft([h, e, u, l], X)', - [{'X': '[e, u, l, h]'}]), - ('shiftleft([h, A, B, l, c], [x, y, C, D, E])', - [{'A': 'x', 'B': 'y', 'C': 'l', 'D': 'c', 'E': 'h'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/shiftleft_2/en.py b/prolog/problems/lists/shiftleft_2/en.py deleted file mode 100644 index a8dd5f0..0000000 --- a/prolog/problems/lists/shiftleft_2/en.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'shiftleft/2' -slug = 'shift a list left' - -description = '''\ -

shiftleft(L1, L2): the list L2 is obtained from L1 by shifting elements to the left by one (circular shift).

-
-?- shiftleft([1,2,3,4,5], X).
-  X = [2,3,4,5,1].
-
''' - -hint = {} diff --git a/prolog/problems/lists/shiftleft_2/sl.py b/prolog/problems/lists/shiftleft_2/sl.py deleted file mode 100644 index ae412a6..0000000 --- a/prolog/problems/lists/shiftleft_2/sl.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'shiftleft/2' -slug = 'Premakni elemente seznama za eno mesto v levo' - -description = '''\ -

shiftleft(L1, L2): elemente v seznamu L1 za eno mesto premaknemo v levo ("circular shift").

-
-?- shiftleft([1,2,3,4,5], X).
-  X = [2,3,4,5,1].
-
''' - -hint = {} diff --git a/prolog/problems/lists/shiftright_2/common.py b/prolog/problems/lists/shiftright_2/common.py deleted file mode 100644 index d8a4c9f..0000000 --- a/prolog/problems/lists/shiftright_2/common.py +++ /dev/null @@ -1,50 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 114 -number = 21 -visible = False -facts = None - -solution = '''\ -conc114([], L, L). -conc114([H|T], L2, [H|L]) :- - conc114(T, L2, L). -shiftright(L1, [H|T]) :- - conc114(T, [H], L1). -''' - -test_cases = [ - ('shiftright([i], X)', - [{'X': '[i]'}]), - ('shiftright([h, e, u, l], X)', - [{'X': '[l, h, e, u]'}]), - ('shiftright([h, A, B, l, c], [C, D, x, y, E])', - [{'A': 'x', 'B': 'y', 'C': 'c', 'D': 'h', 'E': 'l'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/shiftright_2/en.py b/prolog/problems/lists/shiftright_2/en.py deleted file mode 100644 index 63e11cf..0000000 --- a/prolog/problems/lists/shiftright_2/en.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'shiftright/2' -slug = 'shift a list right' - -description = '''\ -

shiftright(L1, L2): the list L2 is obtained from L1 by shifting elements to the right by one (circular shift).

-
-?- shiftright([1,2,3,4,5], X).
-  X = [5,1,2,3,4].
-
''' - -hint = {} diff --git a/prolog/problems/lists/shiftright_2/sl.py b/prolog/problems/lists/shiftright_2/sl.py deleted file mode 100644 index 62fca8d..0000000 --- a/prolog/problems/lists/shiftright_2/sl.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'shiftright/2' -slug = 'Premakni elemente seznama za eno mesto v desno' - -description = '''\ -

shiftright(L1, L2): elemente v seznamu L1 za eno mesto premaknemo v desno ("circular shift").

-
-?- shiftright([1,2,3,4,5], X).
-  X = [5,1,2,3,4].
-
''' - -hint = {} diff --git a/prolog/problems/lists/sl.py b/prolog/problems/lists/sl.py index 0c8dd67..0440a44 100644 --- a/prolog/problems/lists/sl.py +++ b/prolog/problems/lists/sl.py @@ -1,5 +1,4 @@ name = 'Seznami' -description = 'Delo s seznami, poudarek na rekurziji.' description = '''\

Seznami diff --git a/prolog/problems/lists/sublist_2/common.py b/prolog/problems/lists/sublist_2/common.py deleted file mode 100644 index 6187ebc..0000000 --- a/prolog/problems/lists/sublist_2/common.py +++ /dev/null @@ -1,53 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 117 -number = 24 -visible = False -facts = None - -solution = '''\ -conc117([], L, L). -conc117([H|T], L2, [H|L]) :- - conc117(T, L2, L). -sublist(L, S) :- - conc117(_, T, L), - conc117(S, _, T). -''' - -test_cases = [ - ('sublist([], X)', - [{'X': '[]'}]), - ('sublist([e, h, A, B, C], [f, a, e])', - [{'A': 'f', 'B': 'a', 'C': 'e'}]), - ('sublist([e, A, l, B], [r, C, k])', - [{'A': 'r', 'B': 'k', 'C': 'l'}]), - ('setof(L, sublist([a, b, c], L), X)', - [{'X': '[[], [a], [a, b], [a, b, c], [b], [b, c], [c]]'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/sublist_2/en.py b/prolog/problems/lists/sublist_2/en.py deleted file mode 100644 index 2697d9b..0000000 --- a/prolog/problems/lists/sublist_2/en.py +++ /dev/null @@ -1,19 +0,0 @@ -# coding=utf-8 - -name = 'sublist/2' -slug = 'generate sublists of a list' - -description = '''\ -

sublist(L, SL): SL is a continuous sublist of the list L.

-
-?- sublist([1,2,3], X).
-  X = [] ;
-  X = [1] ;
-  X = [1,2] ;
-  X = [1,2,3] ;
-  X = [2] ;
-  X = [2,3] ;
-  X = [3].
-
''' - -hint = {} diff --git a/prolog/problems/lists/sublist_2/sl.py b/prolog/problems/lists/sublist_2/sl.py deleted file mode 100644 index cc42219..0000000 --- a/prolog/problems/lists/sublist_2/sl.py +++ /dev/null @@ -1,19 +0,0 @@ -# coding=utf-8 - -name = 'sublist/2' -slug = 'Generiraj vse podsezname danega seznama' - -description = '''\ -

sublist(L, SL): SL je podseznam seznama L. Predikat naj vrne vse možne podsezname, enega po enega.

-
-?- sublist([1,2,3], X).
-  X = [] ;
-  X = [1] ;
-  X = [1,2] ;
-  X = [1,2,3] ;
-  X = [2] ;
-  X = [2,3] ;
-  X = [3].
-
''' - -hint = {} diff --git a/prolog/problems/lists/sum_2/common.py b/prolog/problems/lists/sum_2/common.py deleted file mode 100644 index 000b4b0..0000000 --- a/prolog/problems/lists/sum_2/common.py +++ /dev/null @@ -1,49 +0,0 @@ -# coding=utf-8 - -from operator import itemgetter -import prolog.engine -import server.problems - -id = 118 -number = 25 -visible = False -facts = None - -solution = '''\ -sum([], 0). -sum([H|T], Sum) :- - sum(T, SumT), - Sum is SumT + H. -''' - -test_cases = [ - ('sum([], X)', - [{'X': '0'}]), - ('sum([8, 3, 5, 1], X)', - [{'X': '17'}]), - ('sum([2, -3, 5, 0], X)', - [{'X': '4'}]), -] - -def test(code, aux_code): - n_correct = 0 - engine_id = None - try: - engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): - 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 - -def hint(code, aux_code): - # TODO - return [] diff --git a/prolog/problems/lists/sum_2/en.py b/prolog/problems/lists/sum_2/en.py deleted file mode 100644 index b4dab45..0000000 --- a/prolog/problems/lists/sum_2/en.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'sum/2' -slug = 'find the sum of all elements in list' - -description = '''\ -

sum(L, Sum): Sum is the sum of all elements in the list L.

-
-?- sum([1,2,3], Sum).
-  Sum = 6.
-
''' - -hint = {} diff --git a/prolog/problems/lists/sum_2/sl.py b/prolog/problems/lists/sum_2/sl.py deleted file mode 100644 index cc0423b..0000000 --- a/prolog/problems/lists/sum_2/sl.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -name = 'sum/2' -slug = 'Izračunaj vsoto elementov v seznamu' - -description = '''\ -

sum(L, Sum): Sum je vsota vseh elementov v seznamu L.

-
-?- sum([1,2,3], Sum).
-  Sum = 6.
-
''' - -hint = {} diff --git a/prolog/problems/lists_advanced/common.py b/prolog/problems/lists_advanced/common.py new file mode 100644 index 0000000..d4e77fa --- /dev/null +++ b/prolog/problems/lists_advanced/common.py @@ -0,0 +1,2 @@ +id = 1000 +number = 3 diff --git a/prolog/problems/lists_advanced/count_3/common.py b/prolog/problems/lists_advanced/count_3/common.py new file mode 100644 index 0000000..2953f06 --- /dev/null +++ b/prolog/problems/lists_advanced/count_3/common.py @@ -0,0 +1,54 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 120 +number = 27 +visible = False +facts = None + +solution = '''\ +count(_, [], 0). +count(X, [X|T], N) :- + count(X, T, NT), + N is NT + 1. +count(X, [Y|T], NT) :- + X \== Y, + count(X, T, NT). +''' + +test_cases = [ + ('count(a, [], X)', + [{'X': '0'}]), + ('count(r, [a, r, b, c, r], X)', + [{'X': '2'}]), + ('count(l, [l, l, l, 1, 2, 3], X)', + [{'X': '3'}]), + ('count(z, [a, b, c, z, z], X)', + [{'X': '2'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/count_3/en.py b/prolog/problems/lists_advanced/count_3/en.py new file mode 100644 index 0000000..dd13bc0 --- /dev/null +++ b/prolog/problems/lists_advanced/count_3/en.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'count/3' +slug = 'find the number of occurrences of an element in list' + +description = '''\ +

count(X, L, N): N is the number of times the element X appears in the list L.

+
+?- count(1, [1,2,1,3,1], N).
+  N = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/count_3/sl.py b/prolog/problems/lists_advanced/count_3/sl.py new file mode 100644 index 0000000..98cd6f8 --- /dev/null +++ b/prolog/problems/lists_advanced/count_3/sl.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'count/3' +slug = 'Preštej kolikokrat se element pojavi v seznamu' + +description = '''\ +

count(X, L, N): N je število kolikokrat se element X pojavi v seznamu L.

+
+?- count(1, [1,2,1,3,1], N).
+  N = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/en.py b/prolog/problems/lists_advanced/en.py new file mode 100644 index 0000000..e7ab5b1 --- /dev/null +++ b/prolog/problems/lists_advanced/en.py @@ -0,0 +1,5 @@ +name = 'Lists and arithmetic' +description = '''\ +

+Lists and arithmetic. +

''' diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py new file mode 100644 index 0000000..1236551 --- /dev/null +++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/common.py @@ -0,0 +1,56 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 116 +number = 23 +visible = False +facts = None + +solution = '''\ +evenlen([]). +evenlen([_,_|T]) :- + evenlen(T). + +oddlen([_]). +oddlen([_,_|T]) :- + oddlen(T). +''' + +test_cases = [ + ('evenlen([])', + [{}]), + ('evenlen([r, w, t, q])', + [{}]), + ('\+ evenlen([r, w, t, q, l])', + [{}]), + ('\+ oddlen([r, w, t, q])', + [{}]), + ('oddlen([r, w, t, q, l])', + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py new file mode 100644 index 0000000..a01a41b --- /dev/null +++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/en.py @@ -0,0 +1,18 @@ +# coding=utf-8 + +name = 'evenlen/1 + oddlen/1' +slug = 'check if the length of a list is even or odd' + +description = '''\ +

evenlen(L): the list L has an even number of elements.
+oddlen(L): the list L has an odd number of elements.

+
+?- oddlen([1,2,3,4,5]).
+  true.
+?- oddlen([1,2,3,4]).
+  false.
+?- evenlen([1,2,3,4]).
+  true.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py new file mode 100644 index 0000000..4ca44c2 --- /dev/null +++ b/prolog/problems/lists_advanced/evenlen_1_+_oddlen_1/sl.py @@ -0,0 +1,18 @@ +# coding=utf-8 + +name = 'evenlen/1 + oddlen/1' +slug = 'Brez aritmetike preveri, če je seznam sode ali lihe dolžine' + +description = '''\ +

evenlen(L): seznam L ima sodo število elementov.
+oddlen(L): seznam L ima liho število elementov.

+
+?- oddlen([1,2,3,4,5]).
+  true.
+?- oddlen([1,2,3,4]).
+  false.
+?- evenlen([1,2,3,4]).
+  true.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/len_2/common.py b/prolog/problems/lists_advanced/len_2/common.py new file mode 100644 index 0000000..93a1faa --- /dev/null +++ b/prolog/problems/lists_advanced/len_2/common.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 119 +number = 26 +visible = False +facts = None + +solution = '''\ +len([], 0). +len([_|T], Len) :- + len(T, LenT), + Len is LenT + 1. +''' + +test_cases = [ + ('len([8, 3, 5, 1], X)', + [{'X': '4'}]), + ('len([2, -3, 5, 0, 3], X)', + [{'X': '5'}]), + ('len([], X)', + [{'X': '0'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/len_2/en.py b/prolog/problems/lists_advanced/len_2/en.py new file mode 100644 index 0000000..3ca963e --- /dev/null +++ b/prolog/problems/lists_advanced/len_2/en.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'len/2' +slug = 'find the length of a list' + +description = '''\ +

len(L, Len): Len is the length of the list L.

+
+?- len([1,2,3], Len).
+  Len = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/len_2/sl.py b/prolog/problems/lists_advanced/len_2/sl.py new file mode 100644 index 0000000..0e98272 --- /dev/null +++ b/prolog/problems/lists_advanced/len_2/sl.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'len/2' +slug = 'Izračunaj dolžino danega seznama' + +description = '''\ +

len(L, Len): Len je dolžina seznama L.

+
+?- len([1,2,3], Len).
+  Len = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/max_2/common.py b/prolog/problems/lists_advanced/max_2/common.py new file mode 100644 index 0000000..92cf793 --- /dev/null +++ b/prolog/problems/lists_advanced/max_2/common.py @@ -0,0 +1,53 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 109 +number = 16 +visible = False +facts = None + +solution = '''\ +max([X], X). +max([H|T], Max):- + max(T, Max1), + ( H > Max1, Max is H + ; + H =< Max1, Max is Max1 ). +''' + +test_cases = [ + ('max([15], X)', + [{'X': '15'}]), + ('max([22, 13, 81], X)', + [{'X': '81'}]), + ('max([42, 42, 42, 42], X)', + [{'X': '42'}]), + ('max([-22, -113, -41], X)', + [{'X': '-22'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/max_2/en.py b/prolog/problems/lists_advanced/max_2/en.py new file mode 100644 index 0000000..c4bc7e2 --- /dev/null +++ b/prolog/problems/lists_advanced/max_2/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'max/2' +slug = 'find the largest element in list' + +description = '''\ +

max(L, Max): Max is the largest value in the list L.

+
+?- max([5,4,1,6], M).
+  M = 6.
+?- max([3,2,2], M).
+  M = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/max_2/sl.py b/prolog/problems/lists_advanced/max_2/sl.py new file mode 100644 index 0000000..7a0d07a --- /dev/null +++ b/prolog/problems/lists_advanced/max_2/sl.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'max/2' +slug = 'Poišči največji element v danem seznamu' + +description = '''\ +

max(L, Max): Max je največji element v seznamu L.

+
+?- max([5,4,1,6], M).
+  M = 6.
+?- max([3,2,2], M).
+  M = 3.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/min_2/common.py b/prolog/problems/lists_advanced/min_2/common.py new file mode 100644 index 0000000..213da5a --- /dev/null +++ b/prolog/problems/lists_advanced/min_2/common.py @@ -0,0 +1,53 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 108 +number = 15 +visible = False +facts = None + +solution = '''\ +min([X], X). +min([H|T], Min):- + min(T, Min1), + ( H < Min1, Min is H + ; + H >= Min1, Min is Min1 ). +''' + +test_cases = [ + ('min([15], X)', + [{'X': '15'}]), + ('min([22, 13, 81], X)', + [{'X': '13'}]), + ('min([42, 42, 42, 42], X)', + [{'X': '42'}]), + ('min([-22, 113, 1], X)', + [{'X': '-22'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/min_2/en.py b/prolog/problems/lists_advanced/min_2/en.py new file mode 100644 index 0000000..18f45a6 --- /dev/null +++ b/prolog/problems/lists_advanced/min_2/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'min/2' +slug = 'find the smallest element' + +description = '''\ +

min(L, Min): Min is the smallest value in the list L.

+
+?- min([5,4,1,6], M).
+  M = 1.
+?- min([3,2,2], M).
+  M = 2.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/min_2/sl.py b/prolog/problems/lists_advanced/min_2/sl.py new file mode 100644 index 0000000..703a05e --- /dev/null +++ b/prolog/problems/lists_advanced/min_2/sl.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'min/2' +slug = 'Poišči najmanjši element v danem seznamu' + +description = '''\ +

min(L, Min): Min je najmanjši element v seznamu L.

+
+?- min([5,4,1,6], M).
+  M = 1.
+?- min([3,2,2], M).
+  M = 2.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/palindrome_1/common.py b/prolog/problems/lists_advanced/palindrome_1/common.py new file mode 100644 index 0000000..e9960c6 --- /dev/null +++ b/prolog/problems/lists_advanced/palindrome_1/common.py @@ -0,0 +1,54 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 112 +number = 19 +visible = False +facts = None + +solution = '''\ +conc112([], L, L). +conc112([H|T], L2, [H|L]) :- + conc112(T, L2, L). +rev112([], []). +rev112([H|T], R):- + rev112(T, R1), + conc112(R1, [H], R). +palindrome(L) :- + rev112(L, L). +''' + +test_cases = [ + ('palindrome([])', + [{}]), + ('palindrome([a, b, e, A, B, C])', + [{'A': 'e', 'B': 'b', 'C': 'a'}]), + ('palindrome([b, e, X])', + [{'X': 'b'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/palindrome_1/en.py b/prolog/problems/lists_advanced/palindrome_1/en.py new file mode 100644 index 0000000..48ee8ac --- /dev/null +++ b/prolog/problems/lists_advanced/palindrome_1/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'palindrome/1' +slug = 'check if list is a palindrome' + +description = '''\ +

palindrome(L): the elements of list L are the same when read from the front or back of the list.

+
+?- palindrome([1,2,3,2,1]).
+  true.
+?- palindrome([1,2,3]).
+  false.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/palindrome_1/sl.py b/prolog/problems/lists_advanced/palindrome_1/sl.py new file mode 100644 index 0000000..ad67d3f --- /dev/null +++ b/prolog/problems/lists_advanced/palindrome_1/sl.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'palindrome/1' +slug = 'Preveri, če elementi seznama tvorijo palindrom' + +description = '''\ +

palindrome(L): Elementi seznama L se preberejo v istem vrstnem redu z začetka in s konca seznama.

+
+?- palindrome([1,2,3,2,1]).
+  true.
+?- palindrome([1,2,3]).
+  false.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/rev_2/common.py b/prolog/problems/lists_advanced/rev_2/common.py new file mode 100644 index 0000000..408389a --- /dev/null +++ b/prolog/problems/lists_advanced/rev_2/common.py @@ -0,0 +1,52 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 111 +number = 18 +visible = False +facts = None + +solution = '''\ +conc111([], L, L). +conc111([H|T], L2, [H|L]) :- + conc111(T, L2, L). +rev([], []). +rev([H|T], R):- + rev(T, R1), + conc111(R1, [H], R). +''' + +test_cases = [ + ('rev([], X)', + [{'X': '[]'}]), + ('rev([s, k, c, d, d], X)', + [{'X': '[d, d, c, k, s]'}]), + ('rev(X, [s, k, c, d, d])', + [{'X': '[d, d, c, k, s]'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/rev_2/en.py b/prolog/problems/lists_advanced/rev_2/en.py new file mode 100644 index 0000000..3ae126e --- /dev/null +++ b/prolog/problems/lists_advanced/rev_2/en.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'rev/2' +slug = 'reverse a list' + +description = '''\ +

rev(L1, L2): the list L2 is obtained from L1 by reversing the order of the elements.

+
+?- rev([1,2,3], X).
+  X = [3,2,1].
+?- rev([], X).
+  X = [].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/rev_2/sl.py b/prolog/problems/lists_advanced/rev_2/sl.py new file mode 100644 index 0000000..ab58a1c --- /dev/null +++ b/prolog/problems/lists_advanced/rev_2/sl.py @@ -0,0 +1,15 @@ +# coding=utf-8 + +name = 'rev/2' +slug = 'Obrni seznam' + +description = '''\ +

rev(L1, L2): seznam L2 ima elemente v obratnem vrstnem redu kot seznam L1.

+
+?- rev([1,2,3], X).
+  X = [3,2,1].
+?- rev([], X).
+  X = [].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/shiftleft_2/common.py b/prolog/problems/lists_advanced/shiftleft_2/common.py new file mode 100644 index 0000000..13db28f --- /dev/null +++ b/prolog/problems/lists_advanced/shiftleft_2/common.py @@ -0,0 +1,50 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 113 +number = 20 +visible = False +facts = None + +solution = '''\ +conc113([], L, L). +conc113([H|T], L2, [H|L]) :- + conc113(T, L2, L). +shiftleft([H|T], L2) :- + conc113(T, [H], L2). +''' + +test_cases = [ + ('shiftleft([i], X)', + [{'X': '[i]'}]), + ('shiftleft([h, e, u, l], X)', + [{'X': '[e, u, l, h]'}]), + ('shiftleft([h, A, B, l, c], [x, y, C, D, E])', + [{'A': 'x', 'B': 'y', 'C': 'l', 'D': 'c', 'E': 'h'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/shiftleft_2/en.py b/prolog/problems/lists_advanced/shiftleft_2/en.py new file mode 100644 index 0000000..a8dd5f0 --- /dev/null +++ b/prolog/problems/lists_advanced/shiftleft_2/en.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'shiftleft/2' +slug = 'shift a list left' + +description = '''\ +

shiftleft(L1, L2): the list L2 is obtained from L1 by shifting elements to the left by one (circular shift).

+
+?- shiftleft([1,2,3,4,5], X).
+  X = [2,3,4,5,1].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/shiftleft_2/sl.py b/prolog/problems/lists_advanced/shiftleft_2/sl.py new file mode 100644 index 0000000..ae412a6 --- /dev/null +++ b/prolog/problems/lists_advanced/shiftleft_2/sl.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'shiftleft/2' +slug = 'Premakni elemente seznama za eno mesto v levo' + +description = '''\ +

shiftleft(L1, L2): elemente v seznamu L1 za eno mesto premaknemo v levo ("circular shift").

+
+?- shiftleft([1,2,3,4,5], X).
+  X = [2,3,4,5,1].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/shiftright_2/common.py b/prolog/problems/lists_advanced/shiftright_2/common.py new file mode 100644 index 0000000..d8a4c9f --- /dev/null +++ b/prolog/problems/lists_advanced/shiftright_2/common.py @@ -0,0 +1,50 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 114 +number = 21 +visible = False +facts = None + +solution = '''\ +conc114([], L, L). +conc114([H|T], L2, [H|L]) :- + conc114(T, L2, L). +shiftright(L1, [H|T]) :- + conc114(T, [H], L1). +''' + +test_cases = [ + ('shiftright([i], X)', + [{'X': '[i]'}]), + ('shiftright([h, e, u, l], X)', + [{'X': '[l, h, e, u]'}]), + ('shiftright([h, A, B, l, c], [C, D, x, y, E])', + [{'A': 'x', 'B': 'y', 'C': 'c', 'D': 'h', 'E': 'l'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/shiftright_2/en.py b/prolog/problems/lists_advanced/shiftright_2/en.py new file mode 100644 index 0000000..63e11cf --- /dev/null +++ b/prolog/problems/lists_advanced/shiftright_2/en.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'shiftright/2' +slug = 'shift a list right' + +description = '''\ +

shiftright(L1, L2): the list L2 is obtained from L1 by shifting elements to the right by one (circular shift).

+
+?- shiftright([1,2,3,4,5], X).
+  X = [5,1,2,3,4].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/shiftright_2/sl.py b/prolog/problems/lists_advanced/shiftright_2/sl.py new file mode 100644 index 0000000..62fca8d --- /dev/null +++ b/prolog/problems/lists_advanced/shiftright_2/sl.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'shiftright/2' +slug = 'Premakni elemente seznama za eno mesto v desno' + +description = '''\ +

shiftright(L1, L2): elemente v seznamu L1 za eno mesto premaknemo v desno ("circular shift").

+
+?- shiftright([1,2,3,4,5], X).
+  X = [5,1,2,3,4].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/sl.py b/prolog/problems/lists_advanced/sl.py new file mode 100644 index 0000000..51b4838 --- /dev/null +++ b/prolog/problems/lists_advanced/sl.py @@ -0,0 +1,5 @@ +name = 'Seznami in aritmetika' +description = '''\ +

+Seznami in aritmetika. +

''' diff --git a/prolog/problems/lists_advanced/sublist_2/common.py b/prolog/problems/lists_advanced/sublist_2/common.py new file mode 100644 index 0000000..6187ebc --- /dev/null +++ b/prolog/problems/lists_advanced/sublist_2/common.py @@ -0,0 +1,53 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 117 +number = 24 +visible = False +facts = None + +solution = '''\ +conc117([], L, L). +conc117([H|T], L2, [H|L]) :- + conc117(T, L2, L). +sublist(L, S) :- + conc117(_, T, L), + conc117(S, _, T). +''' + +test_cases = [ + ('sublist([], X)', + [{'X': '[]'}]), + ('sublist([e, h, A, B, C], [f, a, e])', + [{'A': 'f', 'B': 'a', 'C': 'e'}]), + ('sublist([e, A, l, B], [r, C, k])', + [{'A': 'r', 'B': 'k', 'C': 'l'}]), + ('setof(L, sublist([a, b, c], L), X)', + [{'X': '[[], [a], [a, b], [a, b, c], [b], [b, c], [c]]'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/sublist_2/en.py b/prolog/problems/lists_advanced/sublist_2/en.py new file mode 100644 index 0000000..2697d9b --- /dev/null +++ b/prolog/problems/lists_advanced/sublist_2/en.py @@ -0,0 +1,19 @@ +# coding=utf-8 + +name = 'sublist/2' +slug = 'generate sublists of a list' + +description = '''\ +

sublist(L, SL): SL is a continuous sublist of the list L.

+
+?- sublist([1,2,3], X).
+  X = [] ;
+  X = [1] ;
+  X = [1,2] ;
+  X = [1,2,3] ;
+  X = [2] ;
+  X = [2,3] ;
+  X = [3].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/sublist_2/sl.py b/prolog/problems/lists_advanced/sublist_2/sl.py new file mode 100644 index 0000000..cc42219 --- /dev/null +++ b/prolog/problems/lists_advanced/sublist_2/sl.py @@ -0,0 +1,19 @@ +# coding=utf-8 + +name = 'sublist/2' +slug = 'Generiraj vse podsezname danega seznama' + +description = '''\ +

sublist(L, SL): SL je podseznam seznama L. Predikat naj vrne vse možne podsezname, enega po enega.

+
+?- sublist([1,2,3], X).
+  X = [] ;
+  X = [1] ;
+  X = [1,2] ;
+  X = [1,2,3] ;
+  X = [2] ;
+  X = [2,3] ;
+  X = [3].
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/sum_2/common.py b/prolog/problems/lists_advanced/sum_2/common.py new file mode 100644 index 0000000..000b4b0 --- /dev/null +++ b/prolog/problems/lists_advanced/sum_2/common.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +from operator import itemgetter +import prolog.engine +import server.problems + +id = 118 +number = 25 +visible = False +facts = None + +solution = '''\ +sum([], 0). +sum([H|T], Sum) :- + sum(T, SumT), + Sum is SumT + H. +''' + +test_cases = [ + ('sum([], X)', + [{'X': '0'}]), + ('sum([8, 3, 5, 1], X)', + [{'X': '17'}]), + ('sum([2, -3, 5, 0], X)', + [{'X': '4'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.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): + 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 + +def hint(code, aux_code): + # TODO + return [] diff --git a/prolog/problems/lists_advanced/sum_2/en.py b/prolog/problems/lists_advanced/sum_2/en.py new file mode 100644 index 0000000..b4dab45 --- /dev/null +++ b/prolog/problems/lists_advanced/sum_2/en.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'sum/2' +slug = 'find the sum of all elements in list' + +description = '''\ +

sum(L, Sum): Sum is the sum of all elements in the list L.

+
+?- sum([1,2,3], Sum).
+  Sum = 6.
+
''' + +hint = {} diff --git a/prolog/problems/lists_advanced/sum_2/sl.py b/prolog/problems/lists_advanced/sum_2/sl.py new file mode 100644 index 0000000..cc0423b --- /dev/null +++ b/prolog/problems/lists_advanced/sum_2/sl.py @@ -0,0 +1,13 @@ +# coding=utf-8 + +name = 'sum/2' +slug = 'Izračunaj vsoto elementov v seznamu' + +description = '''\ +

sum(L, Sum): Sum je vsota vseh elementov v seznamu L.

+
+?- sum([1,2,3], Sum).
+  Sum = 6.
+
''' + +hint = {} diff --git a/prolog/problems/sets/common.py b/prolog/problems/sets/common.py index 104aa9d..b3335ec 100644 --- a/prolog/problems/sets/common.py +++ b/prolog/problems/sets/common.py @@ -1,2 +1,2 @@ id = 5 -number = 4 +number = 5 diff --git a/prolog/problems/sorting/common.py b/prolog/problems/sorting/common.py index f006f10..4e5aa88 100644 --- a/prolog/problems/sorting/common.py +++ b/prolog/problems/sorting/common.py @@ -1,2 +1,2 @@ id = 3 -number = 3 +number = 4 diff --git a/prolog/problems/trees/common.py b/prolog/problems/trees/common.py index a519878..9cf57f5 100644 --- a/prolog/problems/trees/common.py +++ b/prolog/problems/trees/common.py @@ -1,2 +1,2 @@ id = 6 -number = 5 +number = 6 diff --git a/readme.md b/readme.md index 420120d..da79939 100644 --- a/readme.md +++ b/readme.md @@ -23,6 +23,12 @@ the relevant range below: Python: 20000-29999 Robot: 30000-39999 +Problem group IDs should be chosen from the range: + + Prolog: 1000-1999 + Python: 2000-2999 + Robot: 3000-3999 + Running `scripts/build\_web\_resources.py` in the codeq-server repo will generate JSON files for all problems, and insert new problems, groups and languages in the database. -- cgit v1.2.1