diff options
Diffstat (limited to 'prolog/problems/clp_fd/tobase_3')
-rw-r--r-- | prolog/problems/clp_fd/tobase_3/common.py | 15 | ||||
-rw-r--r-- | prolog/problems/clp_fd/tobase_3/en.py | 16 |
2 files changed, 31 insertions, 0 deletions
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 = {} |