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/license_plates/genexp_2/common.py | 23 +++++++++++++++++++++++ prolog/problems/license_plates/genexp_2/en.py | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 prolog/problems/license_plates/genexp_2/common.py create mode 100644 prolog/problems/license_plates/genexp_2/en.py (limited to 'prolog/problems/license_plates/genexp_2') diff --git a/prolog/problems/license_plates/genexp_2/common.py b/prolog/problems/license_plates/genexp_2/common.py new file mode 100644 index 0000000..a91c392 --- /dev/null +++ b/prolog/problems/license_plates/genexp_2/common.py @@ -0,0 +1,23 @@ +id = 146 +group = 'license_plates' +number = 53 +visible = True +facts = None + +solution = '''\ +memb146(X, [X|_]). +memb146(X, [_|T]) :- + memb146(X, T). + +conc146([], L, L). +conc146([H|T], L2, [H|L]) :- + conc146(T, L2, L). + +genexp([Exp], Exp). +genexp(L, Exp) :- + conc146(Before, [N1,N2|After], L), + memb146(Op, ['+','-','*','/']), + NExp =.. [Op, N1, N2], + conc146(Before, [NExp|After], L1), + genexp(L1, Exp). +''' diff --git a/prolog/problems/license_plates/genexp_2/en.py b/prolog/problems/license_plates/genexp_2/en.py new file mode 100644 index 0000000..c5c61fb --- /dev/null +++ b/prolog/problems/license_plates/genexp_2/en.py @@ -0,0 +1,18 @@ +id = 146 +name = 'genexp/2' +slug = 'generate an arithmetic expression from a list' + +description = '''\ +

genexp(L, E): the expression E is obtained from the list L by inserting arithmetic operators between list elements. Your code should generate all valid solutions.

+
+  ?- genexp([1,2,3], L).
+    L = 1+2+3 ;
+    L = 1+2-3 ;
+    L = (1+2)*3 ;
+    L = (1+2)/3 ;
+    L = 1-2+3 ;
+    L = 1-2-3 ;
+    ...
+
''' + +hint = {} -- cgit v1.2.1