summaryrefslogtreecommitdiff
path: root/prolog/problems/dcg/number_3
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
committerAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
commit95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 (patch)
tree462ba05eb0c4732ca1c97739548801258bf47b40 /prolog/problems/dcg/number_3
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/dcg/number_3')
-rw-r--r--prolog/problems/dcg/number_3/common.py30
-rw-r--r--prolog/problems/dcg/number_3/en.py13
2 files changed, 43 insertions, 0 deletions
diff --git a/prolog/problems/dcg/number_3/common.py b/prolog/problems/dcg/number_3/common.py
new file mode 100644
index 0000000..cc4bde7
--- /dev/null
+++ b/prolog/problems/dcg/number_3/common.py
@@ -0,0 +1,30 @@
+id = 167
+group = 'dcg'
+number = 74
+visible = True
+facts = None
+
+solution = '''\
+number(Num) --> dig167(N), { l2n167(N,Num) }.
+number(Num) --> nonzero167([N]), numb_next167(N1), { l2n167([N|N1],Num) }.
+
+zero167([0]) --> [0].
+nonzero167([N]) --> [N], {memb167(N, [1,2,3,4,5,6,7,8,9])}.
+
+dig167(N) --> zero167(N).
+dig167(N) --> nonzero167(N).
+numb_next167(N) --> dig167(N).
+numb_next167([N|N1]) --> dig167([N]), numb_next167(N1).
+
+memb167(X, [X|_]).
+memb167(X, [_|T]) :-
+ memb167(X, T).
+
+l2n167(L, N) :-
+ l2n167(L, 0, N).
+l2n167([N], S, R) :-
+ R is S*10+N.
+l2n167([H|T], S, N) :-
+ S1 is S*10+H,
+ l2n167(T, S1, N).
+'''
diff --git a/prolog/problems/dcg/number_3/en.py b/prolog/problems/dcg/number_3/en.py
new file mode 100644
index 0000000..a7a22fa
--- /dev/null
+++ b/prolog/problems/dcg/number_3/en.py
@@ -0,0 +1,13 @@
+id = 167
+name = 'number/3'
+slug = 'numbers with meaning'
+
+description = '''\
+<p>Write a DCG with the starting symbol <code>number</code> for the language of non-negative integers. The numbers may contain leading zeros. The meaning of a word in this language is the numeric value of the represented number.</p>
+<pre>
+ ?- number(N, [1,2,3,4], []).
+ N = 1234.
+</pre>
+'''
+
+hint = {}