From 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 18 Aug 2015 16:06:19 +0200 Subject: Exported all problems from the SQLite database into the new directory structure. --- prolog/problems/lists/conc_3/common.py | 11 +++++++++++ prolog/problems/lists/conc_3/en.py | 14 ++++++++++++++ prolog/problems/lists/count_3/common.py | 15 +++++++++++++++ prolog/problems/lists/count_3/en.py | 12 ++++++++++++ prolog/problems/lists/del_3/common.py | 11 +++++++++++ prolog/problems/lists/del_3/en.py | 19 +++++++++++++++++++ prolog/problems/lists/divide_3/common.py | 12 ++++++++++++ prolog/problems/lists/divide_3/en.py | 14 ++++++++++++++ prolog/problems/lists/dup_2/common.py | 11 +++++++++++ prolog/problems/lists/dup_2/en.py | 14 ++++++++++++++ prolog/problems/lists/evenlen_1_+_oddlen_1/common.py | 15 +++++++++++++++ prolog/problems/lists/evenlen_1_+_oddlen_1/en.py | 17 +++++++++++++++++ prolog/problems/lists/insert_3/common.py | 13 +++++++++++++ prolog/problems/lists/insert_3/en.py | 14 ++++++++++++++ prolog/problems/lists/len_2/common.py | 12 ++++++++++++ prolog/problems/lists/len_2/en.py | 12 ++++++++++++ prolog/problems/lists/max_2/common.py | 14 ++++++++++++++ prolog/problems/lists/max_2/en.py | 14 ++++++++++++++ prolog/problems/lists/memb_2/common.py | 11 +++++++++++ prolog/problems/lists/memb_2/en.py | 16 ++++++++++++++++ prolog/problems/lists/min_2/common.py | 14 ++++++++++++++ prolog/problems/lists/min_2/en.py | 14 ++++++++++++++ prolog/problems/lists/palindrome_1/common.py | 17 +++++++++++++++++ prolog/problems/lists/palindrome_1/en.py | 14 ++++++++++++++ prolog/problems/lists/permute_2/common.py | 15 +++++++++++++++ prolog/problems/lists/permute_2/en.py | 17 +++++++++++++++++ prolog/problems/lists/rev_2/common.py | 15 +++++++++++++++ prolog/problems/lists/rev_2/en.py | 14 ++++++++++++++ prolog/problems/lists/shiftleft_2/common.py | 13 +++++++++++++ prolog/problems/lists/shiftleft_2/en.py | 12 ++++++++++++ prolog/problems/lists/shiftright_2/common.py | 13 +++++++++++++ prolog/problems/lists/shiftright_2/en.py | 12 ++++++++++++ prolog/problems/lists/sublist_2/common.py | 14 ++++++++++++++ prolog/problems/lists/sublist_2/en.py | 18 ++++++++++++++++++ prolog/problems/lists/sum_2/common.py | 12 ++++++++++++ prolog/problems/lists/sum_2/en.py | 12 ++++++++++++ 36 files changed, 497 insertions(+) create mode 100644 prolog/problems/lists/conc_3/common.py create mode 100644 prolog/problems/lists/conc_3/en.py create mode 100644 prolog/problems/lists/count_3/common.py create mode 100644 prolog/problems/lists/count_3/en.py create mode 100644 prolog/problems/lists/del_3/common.py create mode 100644 prolog/problems/lists/del_3/en.py create mode 100644 prolog/problems/lists/divide_3/common.py create mode 100644 prolog/problems/lists/divide_3/en.py create mode 100644 prolog/problems/lists/dup_2/common.py create mode 100644 prolog/problems/lists/dup_2/en.py create mode 100644 prolog/problems/lists/evenlen_1_+_oddlen_1/common.py create mode 100644 prolog/problems/lists/evenlen_1_+_oddlen_1/en.py create mode 100644 prolog/problems/lists/insert_3/common.py create mode 100644 prolog/problems/lists/insert_3/en.py create mode 100644 prolog/problems/lists/len_2/common.py create mode 100644 prolog/problems/lists/len_2/en.py create mode 100644 prolog/problems/lists/max_2/common.py create mode 100644 prolog/problems/lists/max_2/en.py create mode 100644 prolog/problems/lists/memb_2/common.py create mode 100644 prolog/problems/lists/memb_2/en.py create mode 100644 prolog/problems/lists/min_2/common.py create mode 100644 prolog/problems/lists/min_2/en.py create mode 100644 prolog/problems/lists/palindrome_1/common.py create mode 100644 prolog/problems/lists/palindrome_1/en.py create mode 100644 prolog/problems/lists/permute_2/common.py create mode 100644 prolog/problems/lists/permute_2/en.py create mode 100644 prolog/problems/lists/rev_2/common.py create mode 100644 prolog/problems/lists/rev_2/en.py create mode 100644 prolog/problems/lists/shiftleft_2/common.py create mode 100644 prolog/problems/lists/shiftleft_2/en.py create mode 100644 prolog/problems/lists/shiftright_2/common.py create mode 100644 prolog/problems/lists/shiftright_2/en.py create mode 100644 prolog/problems/lists/sublist_2/common.py create mode 100644 prolog/problems/lists/sublist_2/en.py create mode 100644 prolog/problems/lists/sum_2/common.py create mode 100644 prolog/problems/lists/sum_2/en.py (limited to 'prolog/problems/lists') diff --git a/prolog/problems/lists/conc_3/common.py b/prolog/problems/lists/conc_3/common.py new file mode 100644 index 0000000..29a3919 --- /dev/null +++ b/prolog/problems/lists/conc_3/common.py @@ -0,0 +1,11 @@ +id = 104 +group = 'lists' +number = 12 +visible = True +facts = None + +solution = '''\ +conc([], L, L). +conc([H|T], L2, [H|L]) :- + conc(T, L2, L). +''' diff --git a/prolog/problems/lists/conc_3/en.py b/prolog/problems/lists/conc_3/en.py new file mode 100644 index 0000000..3e127c0 --- /dev/null +++ b/prolog/problems/lists/conc_3/en.py @@ -0,0 +1,14 @@ +id = 104 +name = 'conc/3' +slug = 'concatenate two lists' + +description = '''\ +

conc(L1, L2, L): the list L is obtained by appending the elements of L2 to L1.

+
+  ?- conc([1,2], [3,4], X).
+    X = [1,2,3,4].
+  ?- conc(X, [], [1,2,3]).
+    X = [1,2,3].
+
''' + +hint = {} diff --git a/prolog/problems/lists/count_3/common.py b/prolog/problems/lists/count_3/common.py new file mode 100644 index 0000000..583ad6b --- /dev/null +++ b/prolog/problems/lists/count_3/common.py @@ -0,0 +1,15 @@ +id = 120 +group = 'lists' +number = 27 +visible = True +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). +''' diff --git a/prolog/problems/lists/count_3/en.py b/prolog/problems/lists/count_3/en.py new file mode 100644 index 0000000..799594e --- /dev/null +++ b/prolog/problems/lists/count_3/en.py @@ -0,0 +1,12 @@ +id = 120 +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/del_3/common.py b/prolog/problems/lists/del_3/common.py new file mode 100644 index 0000000..1e99959 --- /dev/null +++ b/prolog/problems/lists/del_3/common.py @@ -0,0 +1,11 @@ +id = 105 +group = 'lists' +number = 11 +visible = True +facts = None + +solution = '''\ +del(X, [X|T], T). +del(X, [Y|T], [Y|L]) :- + del(X, T, L). +''' diff --git a/prolog/problems/lists/del_3/en.py b/prolog/problems/lists/del_3/en.py new file mode 100644 index 0000000..a0f0cd3 --- /dev/null +++ b/prolog/problems/lists/del_3/en.py @@ -0,0 +1,19 @@ +id = 105 +name = 'del/3' +slug = 'delete an element from list' + +description = '''\ +

del(X, L1, L2): the list L2 is obtained from L1 by deleting element X.

+
+  ?- del(1, [1,2,3], L).
+    L = [2,3].
+  ?- del(2, [1,2,3,2,5], L).
+    L = [1,3,2,5] ;
+    L = [1,2,3,5].
+  ?- del(X, [1,2,3], L).
+    X = 1, L = [2,3] ;
+    X = 2, L = [1,3] ;
+    X = 3, L = [1,2].
+
''' + +hint = {} diff --git a/prolog/problems/lists/divide_3/common.py b/prolog/problems/lists/divide_3/common.py new file mode 100644 index 0000000..901d2f4 --- /dev/null +++ b/prolog/problems/lists/divide_3/common.py @@ -0,0 +1,12 @@ +id = 115 +group = 'lists' +number = 22 +visible = True +facts = None + +solution = '''\ +divide([], [], []). +divide([X], [X], []). +divide([H1,H2|T], [H1|L1], [H2|L2]) :- + divide(T, L1, L2). +''' diff --git a/prolog/problems/lists/divide_3/en.py b/prolog/problems/lists/divide_3/en.py new file mode 100644 index 0000000..1a8d94e --- /dev/null +++ b/prolog/problems/lists/divide_3/en.py @@ -0,0 +1,14 @@ +id = 115 +name = 'divide/3' +slug = 'split a list into parts of roughly equal length' + +description = '''\ +

divide(L, L1, L2): the list L1 contains elements at odd positions in L, and the list L2 contains the elements at even positions in L.

+
+  ?- divide([a,b,c,d,e,f,g], X, Y).
+    X = [a,c,e,g], Y = [b,d,f].
+  ?- divide([a,b,c,d,e,f], X, Y).
+    X = [a,c,e], Y = [b,d,f].
+
''' + +hint = {} diff --git a/prolog/problems/lists/dup_2/common.py b/prolog/problems/lists/dup_2/common.py new file mode 100644 index 0000000..37a0842 --- /dev/null +++ b/prolog/problems/lists/dup_2/common.py @@ -0,0 +1,11 @@ +id = 110 +group = 'lists' +number = 17 +visible = True +facts = None + +solution = '''\ +dup([], []). +dup([H|T], [H,H|TT]) :- + dup(T, TT). +''' diff --git a/prolog/problems/lists/dup_2/en.py b/prolog/problems/lists/dup_2/en.py new file mode 100644 index 0000000..d6aef71 --- /dev/null +++ b/prolog/problems/lists/dup_2/en.py @@ -0,0 +1,14 @@ +id = 110 +name = 'dup/2' +slug = 'duplicate the elements of a list' + +description = '''\ +

dup(L1, L2): the list L2 is obtained from L1 by duplicating every element.

+
+  ?- dup([1,2], X).
+    X = [1,1,2,2].
+  ?- dup([1,2,3], X).
+    X = [1,1,2,2,3,3].
+
''' + +hint = {} diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py new file mode 100644 index 0000000..2735965 --- /dev/null +++ b/prolog/problems/lists/evenlen_1_+_oddlen_1/common.py @@ -0,0 +1,15 @@ +id = 116 +group = 'lists' +number = 23 +visible = True +facts = None + +solution = '''\ +evenlen([]). +evenlen([_,_|T]) :- + evenlen(T). + +oddlen([_]). +oddlen([_,_|T]) :- + oddlen(T). +''' diff --git a/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py b/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py new file mode 100644 index 0000000..d1957d1 --- /dev/null +++ b/prolog/problems/lists/evenlen_1_+_oddlen_1/en.py @@ -0,0 +1,17 @@ +id = 116 +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/insert_3/common.py b/prolog/problems/lists/insert_3/common.py new file mode 100644 index 0000000..fa3a937 --- /dev/null +++ b/prolog/problems/lists/insert_3/common.py @@ -0,0 +1,13 @@ +id = 106 +group = 'lists' +number = 13 +visible = True +facts = None + +solution = '''\ +del106(X, [X|T], T). +del106(X, [Y|T], [Y|L]) :- + del106(X, T, L). +insert(X, List, BigList) :- + del106(X, BigList, List). +''' diff --git a/prolog/problems/lists/insert_3/en.py b/prolog/problems/lists/insert_3/en.py new file mode 100644 index 0000000..a4a1128 --- /dev/null +++ b/prolog/problems/lists/insert_3/en.py @@ -0,0 +1,14 @@ +id = 106 +name = 'insert/3' +slug = 'insert an element into list' + +description = '''\ +

insert(X, L1, L2): the list L2 is obtained from L1 by inserting the element X at arbitrary position.

+
+  ?- insert(1, [2,3], L).
+    L = [1,2,3] ;
+    L = [2,1,3] ;
+    L = [2,3,1].
+
''' + +hint = {} diff --git a/prolog/problems/lists/len_2/common.py b/prolog/problems/lists/len_2/common.py new file mode 100644 index 0000000..62be9cc --- /dev/null +++ b/prolog/problems/lists/len_2/common.py @@ -0,0 +1,12 @@ +id = 119 +group = 'lists' +number = 26 +visible = True +facts = None + +solution = '''\ +len([], 0). +len([_|T], Len) :- + len(T, LenT), + Len is LenT + 1. +''' diff --git a/prolog/problems/lists/len_2/en.py b/prolog/problems/lists/len_2/en.py new file mode 100644 index 0000000..b3e277c --- /dev/null +++ b/prolog/problems/lists/len_2/en.py @@ -0,0 +1,12 @@ +id = 119 +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/max_2/common.py b/prolog/problems/lists/max_2/common.py new file mode 100644 index 0000000..65e5a70 --- /dev/null +++ b/prolog/problems/lists/max_2/common.py @@ -0,0 +1,14 @@ +id = 109 +group = 'lists' +number = 16 +visible = True +facts = None + +solution = '''\ +max([X], X). +max([H|T], Max):- + max(T, Max1), + ( H > Max1, Max is H + ; + H =< Max1, Max is Max1 ). +''' diff --git a/prolog/problems/lists/max_2/en.py b/prolog/problems/lists/max_2/en.py new file mode 100644 index 0000000..dfb4d60 --- /dev/null +++ b/prolog/problems/lists/max_2/en.py @@ -0,0 +1,14 @@ +id = 109 +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/memb_2/common.py b/prolog/problems/lists/memb_2/common.py new file mode 100644 index 0000000..32d9125 --- /dev/null +++ b/prolog/problems/lists/memb_2/common.py @@ -0,0 +1,11 @@ +id = 103 +group = 'lists' +number = 10 +visible = True +facts = None + +solution = '''\ +memb(X, [X|_]). +memb(X, [_|T]) :- + memb(X, T). +''' diff --git a/prolog/problems/lists/memb_2/en.py b/prolog/problems/lists/memb_2/en.py new file mode 100644 index 0000000..fca82b7 --- /dev/null +++ b/prolog/problems/lists/memb_2/en.py @@ -0,0 +1,16 @@ +id = 103 +name = 'memb/2' +slug = 'find elements in list' + +description = '''\ +

memb(M, L): M is an element of list L.

+
+  ?- memb(X, [1,2,3]).
+    X = 1 ;
+    X = 2 ;
+    X = 3.
+  ?- memb(1, [3,2,X]).
+    X = 1.
+
''' + +hint = {} diff --git a/prolog/problems/lists/min_2/common.py b/prolog/problems/lists/min_2/common.py new file mode 100644 index 0000000..7e9a0bc --- /dev/null +++ b/prolog/problems/lists/min_2/common.py @@ -0,0 +1,14 @@ +id = 108 +group = 'lists' +number = 15 +visible = True +facts = None + +solution = '''\ +min([X], X). +min([H|T], Min):- + min(T, Min1), + ( H < Min1, Min is H + ; + H >= Min1, Min is Min1 ). +''' diff --git a/prolog/problems/lists/min_2/en.py b/prolog/problems/lists/min_2/en.py new file mode 100644 index 0000000..a0a8e74 --- /dev/null +++ b/prolog/problems/lists/min_2/en.py @@ -0,0 +1,14 @@ +id = 108 +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/palindrome_1/common.py b/prolog/problems/lists/palindrome_1/common.py new file mode 100644 index 0000000..8929fd9 --- /dev/null +++ b/prolog/problems/lists/palindrome_1/common.py @@ -0,0 +1,17 @@ +id = 112 +group = 'lists' +number = 19 +visible = True +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). +''' diff --git a/prolog/problems/lists/palindrome_1/en.py b/prolog/problems/lists/palindrome_1/en.py new file mode 100644 index 0000000..c1b8971 --- /dev/null +++ b/prolog/problems/lists/palindrome_1/en.py @@ -0,0 +1,14 @@ +id = 112 +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/permute_2/common.py b/prolog/problems/lists/permute_2/common.py new file mode 100644 index 0000000..8e0386c --- /dev/null +++ b/prolog/problems/lists/permute_2/common.py @@ -0,0 +1,15 @@ +id = 107 +group = 'lists' +number = 14 +visible = True +facts = None + +solution = '''\ +del107(X, [X|T], T). +del107(X, [Y|T], [Y|L]) :- + del107(X, T, L). +permute([], []). +permute(L, [X|P]) :- + del107(X, L, L1), + permute(L1, P). +''' diff --git a/prolog/problems/lists/permute_2/en.py b/prolog/problems/lists/permute_2/en.py new file mode 100644 index 0000000..8898c83 --- /dev/null +++ b/prolog/problems/lists/permute_2/en.py @@ -0,0 +1,17 @@ +id = 107 +name = 'permute/2' +slug = 'generate permutations of a list' + +description = '''\ +

permute(L1, L2): the list L2 is a permutation of the elements of the list L1.

+
+  ?- permute([1,2,3], L).
+    L = [1,2,3] ;
+    L = [1,3,2] ;
+    L = [2,1,3] ;
+    L = [2,3,1] ;
+    L = [3,1,2] ;
+    L = [3,2,1].
+
''' + +hint = {} diff --git a/prolog/problems/lists/rev_2/common.py b/prolog/problems/lists/rev_2/common.py new file mode 100644 index 0000000..79c5fca --- /dev/null +++ b/prolog/problems/lists/rev_2/common.py @@ -0,0 +1,15 @@ +id = 111 +group = 'lists' +number = 18 +visible = True +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). +''' diff --git a/prolog/problems/lists/rev_2/en.py b/prolog/problems/lists/rev_2/en.py new file mode 100644 index 0000000..9cacc95 --- /dev/null +++ b/prolog/problems/lists/rev_2/en.py @@ -0,0 +1,14 @@ +id = 111 +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([], X).
+    X = [].
+  ?- rev([1,2,3], X).
+    X = [3,2,1].
+
''' + +hint = {} diff --git a/prolog/problems/lists/shiftleft_2/common.py b/prolog/problems/lists/shiftleft_2/common.py new file mode 100644 index 0000000..a8d56a7 --- /dev/null +++ b/prolog/problems/lists/shiftleft_2/common.py @@ -0,0 +1,13 @@ +id = 113 +group = 'lists' +number = 20 +visible = True +facts = None + +solution = '''\ +conc113([], L, L). +conc113([H|T], L2, [H|L]) :- + conc113(T, L2, L). +shiftleft([H|T], L2) :- + conc113(T, [H], L2). +''' diff --git a/prolog/problems/lists/shiftleft_2/en.py b/prolog/problems/lists/shiftleft_2/en.py new file mode 100644 index 0000000..0f4b807 --- /dev/null +++ b/prolog/problems/lists/shiftleft_2/en.py @@ -0,0 +1,12 @@ +id = 113 +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/shiftright_2/common.py b/prolog/problems/lists/shiftright_2/common.py new file mode 100644 index 0000000..3d5c3a5 --- /dev/null +++ b/prolog/problems/lists/shiftright_2/common.py @@ -0,0 +1,13 @@ +id = 114 +group = 'lists' +number = 21 +visible = True +facts = None + +solution = '''\ +conc114([], L, L). +conc114([H|T], L2, [H|L]) :- + conc114(T, L2, L). +shiftright(L1, [H|T]) :- + conc114(T, [H], L1). +''' diff --git a/prolog/problems/lists/shiftright_2/en.py b/prolog/problems/lists/shiftright_2/en.py new file mode 100644 index 0000000..8e2a57c --- /dev/null +++ b/prolog/problems/lists/shiftright_2/en.py @@ -0,0 +1,12 @@ +id = 114 +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/sublist_2/common.py b/prolog/problems/lists/sublist_2/common.py new file mode 100644 index 0000000..84c0bc8 --- /dev/null +++ b/prolog/problems/lists/sublist_2/common.py @@ -0,0 +1,14 @@ +id = 117 +group = 'lists' +number = 24 +visible = True +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). +''' diff --git a/prolog/problems/lists/sublist_2/en.py b/prolog/problems/lists/sublist_2/en.py new file mode 100644 index 0000000..5b6808b --- /dev/null +++ b/prolog/problems/lists/sublist_2/en.py @@ -0,0 +1,18 @@ +id = 117 +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/sum_2/common.py b/prolog/problems/lists/sum_2/common.py new file mode 100644 index 0000000..14b0614 --- /dev/null +++ b/prolog/problems/lists/sum_2/common.py @@ -0,0 +1,12 @@ +id = 118 +group = 'lists' +number = 25 +visible = True +facts = None + +solution = '''\ +sum([], 0). +sum([H|T], Sum) :- + sum(T, SumT), + Sum is SumT + H. +''' diff --git a/prolog/problems/lists/sum_2/en.py b/prolog/problems/lists/sum_2/en.py new file mode 100644 index 0000000..8db0e67 --- /dev/null +++ b/prolog/problems/lists/sum_2/en.py @@ -0,0 +1,12 @@ +id = 118 +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 = {} -- cgit v1.2.1