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/clp_fd/gcd_3/common.py | 16 ++++++++++++++++ prolog/problems/clp_fd/gcd_3/en.py | 13 +++++++++++++ prolog/problems/clp_fd/magic_1/common.py | 17 +++++++++++++++++ prolog/problems/clp_fd/magic_1/en.py | 13 +++++++++++++ prolog/problems/clp_fd/puzzle_abc_3/common.py | 14 ++++++++++++++ prolog/problems/clp_fd/puzzle_abc_3/en.py | 9 +++++++++ prolog/problems/clp_fd/puzzle_beth_1/common.py | 9 +++++++++ prolog/problems/clp_fd/puzzle_beth_1/en.py | 10 ++++++++++ prolog/problems/clp_fd/puzzle_momson_2/common.py | 14 ++++++++++++++ prolog/problems/clp_fd/puzzle_momson_2/en.py | 9 +++++++++ prolog/problems/clp_fd/puzzle_ratio_2/common.py | 17 +++++++++++++++++ prolog/problems/clp_fd/puzzle_ratio_2/en.py | 9 +++++++++ prolog/problems/clp_fd/tobase_3/common.py | 15 +++++++++++++++ prolog/problems/clp_fd/tobase_3/en.py | 16 ++++++++++++++++ 14 files changed, 181 insertions(+) create mode 100644 prolog/problems/clp_fd/gcd_3/common.py create mode 100644 prolog/problems/clp_fd/gcd_3/en.py create mode 100644 prolog/problems/clp_fd/magic_1/common.py create mode 100644 prolog/problems/clp_fd/magic_1/en.py create mode 100644 prolog/problems/clp_fd/puzzle_abc_3/common.py create mode 100644 prolog/problems/clp_fd/puzzle_abc_3/en.py create mode 100644 prolog/problems/clp_fd/puzzle_beth_1/common.py create mode 100644 prolog/problems/clp_fd/puzzle_beth_1/en.py create mode 100644 prolog/problems/clp_fd/puzzle_momson_2/common.py create mode 100644 prolog/problems/clp_fd/puzzle_momson_2/en.py create mode 100644 prolog/problems/clp_fd/puzzle_ratio_2/common.py create mode 100644 prolog/problems/clp_fd/puzzle_ratio_2/en.py create mode 100644 prolog/problems/clp_fd/tobase_3/common.py create mode 100644 prolog/problems/clp_fd/tobase_3/en.py (limited to 'prolog/problems/clp_fd') 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 = '''\ +

gcd(X, Y, GCD): GCD is the greatest common divisor of X and Y. Implement this predicate using constraints.

+

Hint: try writing a predicate to find all common divisors of two numbers first.

+
+  ?- gcd(36, 84, GCD).
+    GCD = 12.
+
''' + +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 = '''\ +

magic(S): the list S represents a 3×3 magic square (S 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.

+
+  ?- magic(S).
+    S = [2, 7, 6, 9, 5, 1, 4, 3, 8] ;
+    …
+
''' + +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 = '''\ +

Person A is two years older than B who is twice as old as C. The total of the ages of A, B and C is 27.

+

Write the predicate puzzle_abc(A, B, C) that finds the ages of the three people.

''' + +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 = '''\ +

When asked how old she was, Beth replied "In two years I will be twice as old as I was five years ago".

+

Write the predicate puzzle_beth(X) that finds her current age as X.

+''' + +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 = '''\ +

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?

+

Write the predicate puzzle_momson(M, S) that finds the ages of mother M and son S.

''' + +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 = '''\ +

Present ages of A and B are in the ratio of 5:4. In three years the ratio of their ages will become 11:9.

+

Write the predicate puzzle_ratio(A, B) that finds the ages of A and B.

''' + +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 = '''\ +

tobase(Number, B, X): given a Number in the decimal system (base 10), X represents the same number in the system with base B. Implement this predicate using constraints. Limit the value of B to the interval [2..10].

+
+  ?- tobase(42, 2, X).
+    X = 101010.
+  ?- tobase(N, 2, 101010).
+    N = 42.
+  ?- tobase(42, B, 101010).
+    B = 2.
+
''' + +hint = {} -- cgit v1.2.1