diff options
author | Aleš Smodiš <aless@guru.si> | 2015-08-18 16:06:19 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-18 16:06:19 +0200 |
commit | 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 (patch) | |
tree | 462ba05eb0c4732ca1c97739548801258bf47b40 /prolog/problems/license_plates/genexp_2 |
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/license_plates/genexp_2')
-rw-r--r-- | prolog/problems/license_plates/genexp_2/common.py | 23 | ||||
-rw-r--r-- | prolog/problems/license_plates/genexp_2/en.py | 18 |
2 files changed, 41 insertions, 0 deletions
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 = '''\ +<p><code>genexp(L, E)</code>: the expression <code>E</code> is obtained from the list <code>L</code> by inserting arithmetic operators between list elements. Your code should generate all valid solutions.</p> +<pre> + ?- 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 ; + ... +</pre>''' + +hint = {} |