diff options
Diffstat (limited to 'prolog/problems/clp_fd/tobase_3')
-rw-r--r-- | prolog/problems/clp_fd/tobase_3/common.py | 43 | ||||
-rw-r--r-- | prolog/problems/clp_fd/tobase_3/sl.py | 17 |
2 files changed, 60 insertions, 0 deletions
diff --git a/prolog/problems/clp_fd/tobase_3/common.py b/prolog/problems/clp_fd/tobase_3/common.py index 5d160d7..3783396 100644 --- a/prolog/problems/clp_fd/tobase_3/common.py +++ b/prolog/problems/clp_fd/tobase_3/common.py @@ -1,5 +1,9 @@ # coding=utf-8 +from operator import itemgetter +import prolog.engine +import server.problems + id = 150 number = 62 visible = True @@ -14,3 +18,42 @@ tobase(N, B, Nb) :- Rem #>= 0, Rem #< B, Nb #= Nb1 * 10 + Rem, tobase(N1, B, Nb1).''' + +test_cases = [ + ('tobase(214, 2, X)', + [{'X': '11010110'}]), + ('tobase(321, 7, X)', + [{'X': '636'}]), + ('tobase(X, 8, 777)', + [{'X': '511'}]), + ('tobase(X, 8, 132)', + [{'X': '90'}]), + ('tobase(653, X, 10103)', + [{'X': '5'}]), + ('tobase(123, X, 146)', + [{'X': '9'}]), + ('setof(B/N, tobase(123, B, N), X)', + [{'X': '[2/1111011, 3/11120, 4/1323, 5/443, 6/323, 7/234, 8/173, 9/146, 10/123]'}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0): + n_correct += 1 + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + passed = n_correct == len(test_cases) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return passed, hints + +def hint(program, solved_problems): + # TODO + return [] diff --git a/prolog/problems/clp_fd/tobase_3/sl.py b/prolog/problems/clp_fd/tobase_3/sl.py new file mode 100644 index 0000000..a775808 --- /dev/null +++ b/prolog/problems/clp_fd/tobase_3/sl.py @@ -0,0 +1,17 @@ +# coding=utf-8 + +name = 'tobase/3' +slug = 'Pretvori števila v/iz desetiškega sistema' + +description = '''\ +<p><code>tobase(Number, B, X)</code>: število <code>Number</code> je v desetiškem sistemu. <code>X</code> predstavlja to število v sistemu z bazo <code>B</code>. Implementiraj predikat z uporabo omejitev. Omeji vrednost <code>B</code> na 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 = {} |