summaryrefslogtreecommitdiff
path: root/prolog/problems/clp_fd
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/clp_fd
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/clp_fd')
-rw-r--r--prolog/problems/clp_fd/gcd_3/common.py16
-rw-r--r--prolog/problems/clp_fd/gcd_3/en.py13
-rw-r--r--prolog/problems/clp_fd/magic_1/common.py17
-rw-r--r--prolog/problems/clp_fd/magic_1/en.py13
-rw-r--r--prolog/problems/clp_fd/puzzle_abc_3/common.py14
-rw-r--r--prolog/problems/clp_fd/puzzle_abc_3/en.py9
-rw-r--r--prolog/problems/clp_fd/puzzle_beth_1/common.py9
-rw-r--r--prolog/problems/clp_fd/puzzle_beth_1/en.py10
-rw-r--r--prolog/problems/clp_fd/puzzle_momson_2/common.py14
-rw-r--r--prolog/problems/clp_fd/puzzle_momson_2/en.py9
-rw-r--r--prolog/problems/clp_fd/puzzle_ratio_2/common.py17
-rw-r--r--prolog/problems/clp_fd/puzzle_ratio_2/en.py9
-rw-r--r--prolog/problems/clp_fd/tobase_3/common.py15
-rw-r--r--prolog/problems/clp_fd/tobase_3/en.py16
14 files changed, 181 insertions, 0 deletions
diff --git a/prolog/problems/clp_fd/gcd_3/common.py b/prolog/problems/clp_fd/gcd_3/common.py
new file mode 100644
index 0000000..8ab99ef
--- /dev/null
+++ b/prolog/problems/clp_fd/gcd_3/common.py
@@ -0,0 +1,16 @@
+id = 149
+group = 'clp_fd'
+number = 61
+visible = True
+facts = None
+
+solution = '''\
+cd(X, Y, CD):-
+ X #= _ * CD,
+ Y #= _ * CD,
+ indomain(CD).
+
+gcd(X, Y, GCD):-
+ cd(X, Y, GCD),
+ \+ ( cd(X, Y, CD), CD > GCD ).
+'''
diff --git a/prolog/problems/clp_fd/gcd_3/en.py b/prolog/problems/clp_fd/gcd_3/en.py
new file mode 100644
index 0000000..6d64602
--- /dev/null
+++ b/prolog/problems/clp_fd/gcd_3/en.py
@@ -0,0 +1,13 @@
+id = 149
+name = 'gcd/3'
+slug = 'greatest common divisor'
+
+description = '''\
+<p><code>gcd(X, Y, GCD)</code>: <code>GCD</code> is the greatest common divisor of <code>X</code> and <code>Y</code>. Implement this predicate using constraints.</p>
+<p>Hint: try writing a predicate to find <em>all</em> common divisors of two numbers first.</p>
+<pre>
+ ?- gcd(36, 84, GCD).
+ GCD = 12.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/magic_1/common.py b/prolog/problems/clp_fd/magic_1/common.py
new file mode 100644
index 0000000..0308e1d
--- /dev/null
+++ b/prolog/problems/clp_fd/magic_1/common.py
@@ -0,0 +1,17 @@
+id = 151
+group = 'clp_fd'
+number = 60
+visible = True
+facts = None
+
+solution = '''\
+magic(L):-
+ L = [A1,A2,A3,B1,B2,B3,C1,C2,C3],
+ L ins 1..9,
+ all_different(L),
+ A1+A2+A3 #= B1+B2+B3,
+ A1+A2+A3 #= C1+C2+C3,
+ A1+B1+C1 #= A2+B2+C2,
+ A1+B1+C1 #= A3+B3+C3,
+ A1+B2+C3 #= A3+B2+C1,
+ labeling([], L).'''
diff --git a/prolog/problems/clp_fd/magic_1/en.py b/prolog/problems/clp_fd/magic_1/en.py
new file mode 100644
index 0000000..6fcf252
--- /dev/null
+++ b/prolog/problems/clp_fd/magic_1/en.py
@@ -0,0 +1,13 @@
+id = 151
+name = 'magic/1'
+slug = 'generate a 3x3 magic square'
+
+description = '''\
+<p><code>magic(S)</code>: the list <code>S</code> represents a 3×3 magic square (<code>S</code> is a permutation of numbers 1 to 9 - three numbers for each row). The sums of numbers in each row, column and diagonal of a magic squre are equal. Implement this predicate using constraints. Your code should return all possible solutions.</p>
+<pre>
+ ?- magic(S).
+ S = [2, 7, 6, 9, 5, 1, 4, 3, 8] ;
+ …
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_abc_3/common.py b/prolog/problems/clp_fd/puzzle_abc_3/common.py
new file mode 100644
index 0000000..ee5da6f
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_abc_3/common.py
@@ -0,0 +1,14 @@
+id = 153
+group = 'clp_fd'
+number = 57
+visible = True
+facts = None
+
+solution = '''\
+puzzle_abc(A, B, C) :-
+ A #= B + 2,
+ B #= 2 * C,
+ A+B+C #= 27,
+ [A,B,C] ins 0..inf,
+ labeling([], [A,B,C]).
+'''
diff --git a/prolog/problems/clp_fd/puzzle_abc_3/en.py b/prolog/problems/clp_fd/puzzle_abc_3/en.py
new file mode 100644
index 0000000..5385fe2
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_abc_3/en.py
@@ -0,0 +1,9 @@
+id = 153
+name = 'puzzle_abc/3'
+slug = 'age puzzle: abc'
+
+description = '''\
+<p>Person <code>A</code> is two years older than <code>B</code> who is twice as old as <code>C</code>. The total of the ages of A, B and C is 27.</p>
+<p>Write the predicate <code>puzzle_abc(A, B, C)</code> that finds the ages of the three people.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_beth_1/common.py b/prolog/problems/clp_fd/puzzle_beth_1/common.py
new file mode 100644
index 0000000..a7bcfeb
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_beth_1/common.py
@@ -0,0 +1,9 @@
+id = 155
+group = 'clp_fd'
+number = 56
+visible = True
+facts = None
+
+solution = '''\
+puzzle_beth(X) :-
+ X + 2 #= 2*(X-5).'''
diff --git a/prolog/problems/clp_fd/puzzle_beth_1/en.py b/prolog/problems/clp_fd/puzzle_beth_1/en.py
new file mode 100644
index 0000000..7f4ebc2
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_beth_1/en.py
@@ -0,0 +1,10 @@
+id = 155
+name = 'puzzle_beth/1'
+slug = 'age puzzle: beth'
+
+description = '''\
+<p>When asked how old she was, Beth replied "In two years I will be twice as old as I was five years ago".</p>
+<p>Write the predicate <code>puzzle_beth(X)</code> that finds her current age as <code>X</code>.</p>
+'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_momson_2/common.py b/prolog/problems/clp_fd/puzzle_momson_2/common.py
new file mode 100644
index 0000000..f96f403
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_momson_2/common.py
@@ -0,0 +1,14 @@
+id = 152
+group = 'clp_fd'
+number = 58
+visible = True
+facts = None
+
+solution = '''\
+puzzle_momson(M, S) :-
+ M #= 10*A + B,
+ S #= 10*B + A,
+ [A,B] ins 1..9,
+ M + S #= 66,
+ M #> S,
+ labeling([], [M, S]).'''
diff --git a/prolog/problems/clp_fd/puzzle_momson_2/en.py b/prolog/problems/clp_fd/puzzle_momson_2/en.py
new file mode 100644
index 0000000..8fa8a1f
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_momson_2/en.py
@@ -0,0 +1,9 @@
+id = 152
+name = 'puzzle_momson/2'
+slug = 'age puzzle: mom & son'
+
+description = '''\
+<p>The sum of ages of mother and her son is 66. The mother's age is the son's age reversed. How old are they?</p>
+<p>Write the predicate <code>puzzle_momson(M, S)</code> that finds the ages of mother <code>M</code> and son <code>S</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/puzzle_ratio_2/common.py b/prolog/problems/clp_fd/puzzle_ratio_2/common.py
new file mode 100644
index 0000000..ba7585b
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_ratio_2/common.py
@@ -0,0 +1,17 @@
+id = 154
+group = 'clp_fd'
+number = 59
+visible = True
+facts = None
+
+solution = '''\
+puzzle_ratio(A, B) :-
+ A #= 5*X,
+ B #= 4*X,
+ X #> 0,
+ A+3 #= 11*Y,
+ B+3 #= 9*Y,
+ Y #> 0,
+ A #< 200,
+ B #< 200,
+ labeling([], [A, B]).'''
diff --git a/prolog/problems/clp_fd/puzzle_ratio_2/en.py b/prolog/problems/clp_fd/puzzle_ratio_2/en.py
new file mode 100644
index 0000000..aa5b647
--- /dev/null
+++ b/prolog/problems/clp_fd/puzzle_ratio_2/en.py
@@ -0,0 +1,9 @@
+id = 154
+name = 'puzzle_ratio/2'
+slug = 'age puzzle: ratio'
+
+description = '''\
+<p>Present ages of <code>A</code> and <code>B</code> are in the ratio of 5:4. In three years the ratio of their ages will become 11:9.</p>
+<p>Write the predicate <code>puzzle_ratio(A, B)</code> that finds the ages of <code>A</code> and <code>B</code>.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_fd/tobase_3/common.py b/prolog/problems/clp_fd/tobase_3/common.py
new file mode 100644
index 0000000..fb88be0
--- /dev/null
+++ b/prolog/problems/clp_fd/tobase_3/common.py
@@ -0,0 +1,15 @@
+id = 150
+group = 'clp_fd'
+number = 62
+visible = True
+facts = None
+
+solution = '''\
+tobase(0, _, 0) :- !.
+tobase(N, B, Nb) :-
+ B in 2..10,
+ indomain(B),
+ N #= N1 * B + Rem,
+ Rem #>= 0, Rem #< B,
+ Nb #= Nb1 * 10 + Rem,
+ tobase(N1, B, Nb1).'''
diff --git a/prolog/problems/clp_fd/tobase_3/en.py b/prolog/problems/clp_fd/tobase_3/en.py
new file mode 100644
index 0000000..bac8723
--- /dev/null
+++ b/prolog/problems/clp_fd/tobase_3/en.py
@@ -0,0 +1,16 @@
+id = 150
+name = 'tobase/3'
+slug = 'convert numbers from/to the decimal system'
+
+description = '''\
+<p><code>tobase(Number, B, X)</code>: given a <code>Number</code> in the decimal system (base 10), <code>X</code> represents the same number in the system with base <code>B</code>. Implement this predicate using constraints. Limit the value of <code>B</code> to the interval [2..10].</p>
+<pre>
+ ?- tobase(42, 2, X).
+ X = 101010.
+ ?- tobase(N, 2, 101010).
+ N = 42.
+ ?- tobase(42, B, 101010).
+ B = 2.
+</pre>'''
+
+hint = {}