From ce3b6703c153ba5c827996bfa8fd9bfa85fe2adb Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 8 Oct 2015 16:02:17 +0200 Subject: Remove unneeded id field from {en,sl}.py files --- python/problems/functions/greatest/en.py | 1 - python/problems/functions/greatest/sl.py | 1 - python/problems/functions/greatest_absolutist/en.py | 1 - python/problems/functions/greatest_absolutist/sl.py | 1 - python/problems/functions/greatest_negative/en.py | 1 - python/problems/functions/greatest_negative/sl.py | 1 - 6 files changed, 6 deletions(-) (limited to 'python/problems/functions') diff --git a/python/problems/functions/greatest/en.py b/python/problems/functions/greatest/en.py index 8a0c883..acf4672 100644 --- a/python/problems/functions/greatest/en.py +++ b/python/problems/functions/greatest/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 195 name = 'Maximum number' slug = 'Maximum number' diff --git a/python/problems/functions/greatest/sl.py b/python/problems/functions/greatest/sl.py index a7916a5..12e07fe 100644 --- a/python/problems/functions/greatest/sl.py +++ b/python/problems/functions/greatest/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 195 name = 'Največji' slug = 'Največji' diff --git a/python/problems/functions/greatest_absolutist/en.py b/python/problems/functions/greatest_absolutist/en.py index 03614e7..1ede4a9 100644 --- a/python/problems/functions/greatest_absolutist/en.py +++ b/python/problems/functions/greatest_absolutist/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 196 name = 'Greatest absolutist' slug = 'Greatest absolutist' diff --git a/python/problems/functions/greatest_absolutist/sl.py b/python/problems/functions/greatest_absolutist/sl.py index d51cd96..45440b2 100644 --- a/python/problems/functions/greatest_absolutist/sl.py +++ b/python/problems/functions/greatest_absolutist/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 196 name = 'Največji absolutist' slug = 'Največji absolutist' diff --git a/python/problems/functions/greatest_negative/en.py b/python/problems/functions/greatest_negative/en.py index a57cb1f..5c2919a 100644 --- a/python/problems/functions/greatest_negative/en.py +++ b/python/problems/functions/greatest_negative/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 197 name = 'Greatest negativist' slug = 'Greatest negativist' diff --git a/python/problems/functions/greatest_negative/sl.py b/python/problems/functions/greatest_negative/sl.py index ea1e47c..31f1fd6 100644 --- a/python/problems/functions/greatest_negative/sl.py +++ b/python/problems/functions/greatest_negative/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 197 name = 'Največji negativec' slug = 'Največji negativec' -- cgit v1.2.1 From 3d0fde9ac8bc568845cfef8391ea0f9b0fe2f4e6 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 8 Oct 2015 16:13:35 +0200 Subject: Add language/group IDs and group numbers for Prolog --- python/problems/functions/common.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 python/problems/functions/common.py (limited to 'python/problems/functions') diff --git a/python/problems/functions/common.py b/python/problems/functions/common.py new file mode 100644 index 0000000..1367877 --- /dev/null +++ b/python/problems/functions/common.py @@ -0,0 +1 @@ +id = 17 -- cgit v1.2.1 From 84f3426c937d1bb9d44ba25a71706416fbb8b85d Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Oct 2015 11:17:49 +0200 Subject: Added several new problems. They have no tests nor hints implemented. --- python/problems/functions/assign_numbers/common.py | 47 +++++++++++++++++++ python/problems/functions/assign_numbers/en.py | 16 +++++++ python/problems/functions/assign_numbers/sl.py | 34 ++++++++++++++ .../problems/functions/body_mass_index/common.py | 47 +++++++++++++++++++ python/problems/functions/body_mass_index/en.py | 16 +++++++ python/problems/functions/body_mass_index/sl.py | 35 ++++++++++++++ .../problems/functions/body_mass_index_2/common.py | 47 +++++++++++++++++++ python/problems/functions/body_mass_index_2/en.py | 16 +++++++ python/problems/functions/body_mass_index_2/sl.py | 34 ++++++++++++++ python/problems/functions/divisors/common.py | 46 +++++++++++++++++++ python/problems/functions/divisors/en.py | 16 +++++++ python/problems/functions/divisors/sl.py | 26 +++++++++++ python/problems/functions/divisors_sum/common.py | 48 ++++++++++++++++++++ python/problems/functions/divisors_sum/en.py | 16 +++++++ python/problems/functions/divisors_sum/sl.py | 27 +++++++++++ .../problems/functions/friendly_numbers/common.py | 53 ++++++++++++++++++++++ python/problems/functions/friendly_numbers/en.py | 16 +++++++ python/problems/functions/friendly_numbers/sl.py | 37 +++++++++++++++ .../problems/functions/greatest_absolutist/sl.py | 2 +- python/problems/functions/palindrome/common.py | 44 ++++++++++++++++++ python/problems/functions/palindrome/en.py | 16 +++++++ python/problems/functions/palindrome/sl.py | 33 ++++++++++++++ .../functions/palindromic_numbers/common.py | 49 ++++++++++++++++++++ .../problems/functions/palindromic_numbers/en.py | 16 +++++++ .../problems/functions/palindromic_numbers/sl.py | 31 +++++++++++++ .../problems/functions/perfect_numbers/common.py | 51 +++++++++++++++++++++ python/problems/functions/perfect_numbers/en.py | 16 +++++++ python/problems/functions/perfect_numbers/sl.py | 30 ++++++++++++ python/problems/functions/prime_numbers/common.py | 49 ++++++++++++++++++++ python/problems/functions/prime_numbers/en.py | 16 +++++++ python/problems/functions/prime_numbers/sl.py | 27 +++++++++++ 31 files changed, 956 insertions(+), 1 deletion(-) create mode 100644 python/problems/functions/assign_numbers/common.py create mode 100644 python/problems/functions/assign_numbers/en.py create mode 100644 python/problems/functions/assign_numbers/sl.py create mode 100644 python/problems/functions/body_mass_index/common.py create mode 100644 python/problems/functions/body_mass_index/en.py create mode 100644 python/problems/functions/body_mass_index/sl.py create mode 100644 python/problems/functions/body_mass_index_2/common.py create mode 100644 python/problems/functions/body_mass_index_2/en.py create mode 100644 python/problems/functions/body_mass_index_2/sl.py create mode 100644 python/problems/functions/divisors/common.py create mode 100644 python/problems/functions/divisors/en.py create mode 100644 python/problems/functions/divisors/sl.py create mode 100644 python/problems/functions/divisors_sum/common.py create mode 100644 python/problems/functions/divisors_sum/en.py create mode 100644 python/problems/functions/divisors_sum/sl.py create mode 100644 python/problems/functions/friendly_numbers/common.py create mode 100644 python/problems/functions/friendly_numbers/en.py create mode 100644 python/problems/functions/friendly_numbers/sl.py create mode 100644 python/problems/functions/palindrome/common.py create mode 100644 python/problems/functions/palindrome/en.py create mode 100644 python/problems/functions/palindrome/sl.py create mode 100644 python/problems/functions/palindromic_numbers/common.py create mode 100644 python/problems/functions/palindromic_numbers/en.py create mode 100644 python/problems/functions/palindromic_numbers/sl.py create mode 100644 python/problems/functions/perfect_numbers/common.py create mode 100644 python/problems/functions/perfect_numbers/en.py create mode 100644 python/problems/functions/perfect_numbers/sl.py create mode 100644 python/problems/functions/prime_numbers/common.py create mode 100644 python/problems/functions/prime_numbers/en.py create mode 100644 python/problems/functions/prime_numbers/sl.py (limited to 'python/problems/functions') diff --git a/python/problems/functions/assign_numbers/common.py b/python/problems/functions/assign_numbers/common.py new file mode 100644 index 0000000..f00305a --- /dev/null +++ b/python/problems/functions/assign_numbers/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 225 +group = 'lists_and_for' +number = 4 +visible = True + +solution = '''\ +def numbers(xs): + ys = [] + for i in range(len(xs)): + ys.append((i, xs[i])) + return ys +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/assign_numbers/en.py b/python/problems/functions/assign_numbers/en.py new file mode 100644 index 0000000..a68c6c8 --- /dev/null +++ b/python/problems/functions/assign_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 225 +name = 'Assign numbers' +slug = 'Assign numbers' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/assign_numbers/sl.py b/python/problems/functions/assign_numbers/sl.py new file mode 100644 index 0000000..97c0c3a --- /dev/null +++ b/python/problems/functions/assign_numbers/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 225 +name = 'Oštevilči' +slug = 'Oštevilči' + + +description = '''\ +

+Napišite funkcijo numbers(xs), ki vrne seznam oblike [(0, xs[0]), (1, xs[1]), ..., (n, xs[n])]. +Število n je enako dolžini seznama xs minus ena. +

+>>> numbers([4, 4, 4])
+[(0, 4), (1, 4), (2, 4)]
+>>> numbers([5, 1, 4, 2, 3])
+[(0, 5), (1, 1), (2, 4), (3, 2), (4, 3)]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py new file mode 100644 index 0000000..fba7570 --- /dev/null +++ b/python/problems/functions/body_mass_index/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 226 +group = 'functions' +number = 5 +visible = True + +solution = '''\ +def bmi(xs): + ys = [] + for name, weight, height in xs: + ys.append((name, weight / (height / 100)**2)) + return ys +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/body_mass_index/en.py b/python/problems/functions/body_mass_index/en.py new file mode 100644 index 0000000..fb4663f --- /dev/null +++ b/python/problems/functions/body_mass_index/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 226 +name = 'Body mass index' +slug = 'Body mass index' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/body_mass_index/sl.py b/python/problems/functions/body_mass_index/sl.py new file mode 100644 index 0000000..fd67c88 --- /dev/null +++ b/python/problems/functions/body_mass_index/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 226 +name = 'Indeks telesne teže' +slug = 'Indeks telesne teže' + + +description = '''\ +

+Podan imamo seznam trojk: ime osebe, teža, višina, na primer: +

+>>> osebe = [('Ana', 55, 165), ('Berta', 60, 153)]
+
+Napišite funkcijo bmi(osebe), ki na podlagi podanega seznama osebe, sestavi seznam dvojk: ime osebe, indeks telesne teže: +
+>>> bmi(osebe)
+[('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py new file mode 100644 index 0000000..58c7ab1 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 226 +group = 'functions' +number = 6 +visible = True + +solution = '''\ +def bmi2(names, weights, heights): + ys = [] + for name, weight, height in zip(names, weights, heights): + ys.append((name, weight / (height / 100)**2)) + return ys +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/body_mass_index_2/en.py b/python/problems/functions/body_mass_index_2/en.py new file mode 100644 index 0000000..8ce2533 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 226 +name = 'Body mass index 2' +slug = 'Body mass index 2' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/body_mass_index_2/sl.py b/python/problems/functions/body_mass_index_2/sl.py new file mode 100644 index 0000000..21e7fa0 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 226 +name = 'Indeks telesne teže 2' +slug = 'Indeks telesne teže 2' + + +description = '''\ +

+Naloga je podobna prejšnji, le da imamo tokrat podatke v drugačni obliki: +

+>>> imena = ['Ana', 'Berta']
+>>> teze = [55, 60]
+>>> visine = [165, 153]
+>>> bmi2(imena, teze, visine)
+[('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/divisors/common.py b/python/problems/functions/divisors/common.py new file mode 100644 index 0000000..c3e71d8 --- /dev/null +++ b/python/problems/functions/divisors/common.py @@ -0,0 +1,46 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 230 +group = 'functions' +number = 9 +visible = True + +solution = '''\ +def divisors(n): + for i in range(1, n): + if n % i == 0: + print(i) +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/divisors/en.py b/python/problems/functions/divisors/en.py new file mode 100644 index 0000000..d1e71c2 --- /dev/null +++ b/python/problems/functions/divisors/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 230 +name = 'Divisors' +slug = 'Divisors' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/divisors/sl.py b/python/problems/functions/divisors/sl.py new file mode 100644 index 0000000..76b0917 --- /dev/null +++ b/python/problems/functions/divisors/sl.py @@ -0,0 +1,26 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 230 +name = 'Delitelji' +slug = 'Delitelji' + + +description = '''\ +

+Napiši funkcijo divisors(n), ki izpiše vse delitelje števila (brez samega sebe), ki ga vnese uporabnik.

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/divisors_sum/common.py b/python/problems/functions/divisors_sum/common.py new file mode 100644 index 0000000..d6a2b88 --- /dev/null +++ b/python/problems/functions/divisors_sum/common.py @@ -0,0 +1,48 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 231 +group = 'functions' +number = 10 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/divisors_sum/en.py b/python/problems/functions/divisors_sum/en.py new file mode 100644 index 0000000..67806f7 --- /dev/null +++ b/python/problems/functions/divisors_sum/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 231 +name = 'Divisors sum' +slug = 'Divisors sum' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/divisors_sum/sl.py b/python/problems/functions/divisors_sum/sl.py new file mode 100644 index 0000000..47b8719 --- /dev/null +++ b/python/problems/functions/divisors_sum/sl.py @@ -0,0 +1,27 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 231 +name = 'Vsota deliteljev' +slug = 'Vsota deliteljev' + + +description = '''\ +

+Napiši funkcijo divisors_sum(n), ki vrne vsoto vseh deliteljev števila, ki ga vnese uporabnik. +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/friendly_numbers/common.py b/python/problems/functions/friendly_numbers/common.py new file mode 100644 index 0000000..415040e --- /dev/null +++ b/python/problems/functions/friendly_numbers/common.py @@ -0,0 +1,53 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 233 +group = 'functions' +number = 12 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s + +def friendly_number(n): + s = divisors_sum(n) + if n == divisors_sum(s): + return s +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/friendly_numbers/en.py b/python/problems/functions/friendly_numbers/en.py new file mode 100644 index 0000000..ba740ae --- /dev/null +++ b/python/problems/functions/friendly_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 233 +name = 'Friendly numbers' +slug = 'Friendly numbers' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/friendly_numbers/sl.py b/python/problems/functions/friendly_numbers/sl.py new file mode 100644 index 0000000..d1c15ff --- /dev/null +++ b/python/problems/functions/friendly_numbers/sl.py @@ -0,0 +1,37 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 233 +name = 'Prijateljska števila' +slug = 'Prijateljska števila' + + +description = '''\ +

+220 in 284 sta prijateljski števili. Delitelji 220 so 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 in 110. +Če jih seštejemo, dobimo 284. Delitelji 284 pa so 1, 2, 4, 71 in 142. Vsota teh števil pa je 220. +Napiši funkcijo friendly_number(n), ki vrne prijateljsko število številu n, če ga ima, oz. +vrne None, če ga nima. Primer: +

+>>> friendly_number(220)
+284
+>>> friendly_number(222)
+None
+
+

+

Uporabite funkcijo za vsoto deliteljev!

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/greatest_absolutist/sl.py b/python/problems/functions/greatest_absolutist/sl.py index d51cd96..ee33c6d 100644 --- a/python/problems/functions/greatest_absolutist/sl.py +++ b/python/problems/functions/greatest_absolutist/sl.py @@ -101,7 +101,7 @@ V tem primeru se lahko zgodi, da se zanka ne izteče do konca.

''', Tudi to nalogo lahko rešimo s funkcijo max:

 def max_abs(xs):
-    return max(xs, key = lambda x: abs(x))
+    return max(xs, key = abs(x))
 
''', } diff --git a/python/problems/functions/palindrome/common.py b/python/problems/functions/palindrome/common.py new file mode 100644 index 0000000..e012e8d --- /dev/null +++ b/python/problems/functions/palindrome/common.py @@ -0,0 +1,44 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 228 +group = 'functions' +number = 7 +visible = True + +solution = '''\ +def palindrome(s): + return s == s[::-1] +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/palindrome/en.py b/python/problems/functions/palindrome/en.py new file mode 100644 index 0000000..784c395 --- /dev/null +++ b/python/problems/functions/palindrome/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 228 +name = 'Palindrome' +slug = 'Palindrome' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/palindrome/sl.py b/python/problems/functions/palindrome/sl.py new file mode 100644 index 0000000..e005057 --- /dev/null +++ b/python/problems/functions/palindrome/sl.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 228 +name = 'Palindrom' +slug = 'Palindrom' + + +description = '''\ +

+Napišite funkcijo palindrome(s), ki preveri, ali je niz s palindrom. +

+>>> palindrome('pericarezeracirep')
+True
+>>> palindrome('perica')
+False
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/palindromic_numbers/common.py b/python/problems/functions/palindromic_numbers/common.py new file mode 100644 index 0000000..ba518c7 --- /dev/null +++ b/python/problems/functions/palindromic_numbers/common.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 229 +group = 'functions' +number = 8 +visible = True + +solution = '''\ +def palindromic_numbers(): + xs = [] + for i in range(100, 1000): + for j in range(100, 1000): + if str(i * j) == str(i * j)[::-1]: + xs.append(i * j) + return max(xs) +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/palindromic_numbers/en.py b/python/problems/functions/palindromic_numbers/en.py new file mode 100644 index 0000000..5f4ea76 --- /dev/null +++ b/python/problems/functions/palindromic_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 229 +name = 'Palindromic numbers' +slug = 'Palindromic numbers' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/palindromic_numbers/sl.py b/python/problems/functions/palindromic_numbers/sl.py new file mode 100644 index 0000000..8d64bab --- /dev/null +++ b/python/problems/functions/palindromic_numbers/sl.py @@ -0,0 +1,31 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 229 +name = 'Palindromska števila' +slug = 'Palindromska števila' + + +description = '''\ +

+Največje palindromsko število, ki ga lahko dobimo kot produkt dveh dvomestnih števil je 9009 = 91 * 99. +Napišite funkcijo palindromic_number(), ki poišče in vrne največje palindromsko število, +ki ga lahko dobimo kot produkt dveh tromestnih števil. + +Vir: Project Euler, Problem 4. +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/perfect_numbers/common.py b/python/problems/functions/perfect_numbers/common.py new file mode 100644 index 0000000..ad1a7cd --- /dev/null +++ b/python/problems/functions/perfect_numbers/common.py @@ -0,0 +1,51 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 232 +group = 'functions' +number = 11 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s + +def perfect(n): + return n == divisors_sum(n) +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/perfect_numbers/en.py b/python/problems/functions/perfect_numbers/en.py new file mode 100644 index 0000000..a7cb94e --- /dev/null +++ b/python/problems/functions/perfect_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 232 +name = 'Perfect numbers' +slug = 'Perfect numbers' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/perfect_numbers/sl.py b/python/problems/functions/perfect_numbers/sl.py new file mode 100644 index 0000000..a354a17 --- /dev/null +++ b/python/problems/functions/perfect_numbers/sl.py @@ -0,0 +1,30 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 232 +name = 'Popolna števila' +slug = 'Popolna števila' + + +description = '''\ +

+Napiši funkcijo perfect(n), ki vrne True, če je podano število popolno, oz. False, če ni. +Popolna števila so števila, ki so enaka vsoti svojih deliteljev (brez samega sebe). +Primer popolnega števila je 28, saj so njegovi delitelji 1, 2, 4, 7, 14, njihova vsota, 1+2+4+7+14 pa je spet enaka 28. +

+

Uporabite funkcijo za vsoto deliteljev!

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/prime_numbers/common.py b/python/problems/functions/prime_numbers/common.py new file mode 100644 index 0000000..0447c61 --- /dev/null +++ b/python/problems/functions/prime_numbers/common.py @@ -0,0 +1,49 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 234 +group = 'functions' +number = 13 +visible = True + +solution = '''\ +def prime(n): + for i in range(2, n): + for j in range(2, i): + if i % j == 0: + break + else: + print(i) +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + passed = n_correct == len(test_in) + tin = None + tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, code): + tokens = get_tokens(code) + + # run one test first to see if there are any exceptions + answer = python(code=code, inputs=[(None, None)], timeout=1.0) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions/prime_numbers/en.py b/python/problems/functions/prime_numbers/en.py new file mode 100644 index 0000000..87c01a2 --- /dev/null +++ b/python/problems/functions/prime_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 234 +name = 'Prime numbers' +slug = 'Prime numbers' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions/prime_numbers/sl.py b/python/problems/functions/prime_numbers/sl.py new file mode 100644 index 0000000..f6c6b24 --- /dev/null +++ b/python/problems/functions/prime_numbers/sl.py @@ -0,0 +1,27 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 234 +name = 'Praštevila' +slug = 'Praštevila' + + +description = '''\ +

+Napišite funkcijo prime(n), ki izpiše vsa praštevila manjša od n. +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} -- cgit v1.2.1 From 95e107bf9e6a288969e4a83aee1a7062990f3b67 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Oct 2015 16:35:23 +0200 Subject: Fixed testing for most problems. --- python/problems/functions/assign_numbers/common.py | 24 ++++++++++++++--- .../problems/functions/body_mass_index/common.py | 27 ++++++++++++++++--- .../problems/functions/body_mass_index_2/common.py | 26 +++++++++++++++--- python/problems/functions/common.py | 1 + python/problems/functions/divisors/common.py | 30 ++++++++++++++++++--- python/problems/functions/divisors_sum/common.py | 28 ++++++++++++++++--- .../problems/functions/friendly_numbers/common.py | 31 +++++++++++++++++++--- python/problems/functions/friendly_numbers/en.py | 4 +-- python/problems/functions/friendly_numbers/sl.py | 6 ++--- python/problems/functions/greatest/common.py | 4 +++ .../functions/greatest_absolutist/common.py | 4 +++ .../problems/functions/greatest_negative/common.py | 4 +++ python/problems/functions/palindrome/common.py | 31 +++++++++++++++++++--- .../functions/palindromic_numbers/common.py | 28 ++++++++++++++++--- .../problems/functions/perfect_numbers/common.py | 27 ++++++++++++++++--- python/problems/functions/prime_numbers/common.py | 27 ++++++++++++++++--- 16 files changed, 266 insertions(+), 36 deletions(-) (limited to 'python/problems/functions') diff --git a/python/problems/functions/assign_numbers/common.py b/python/problems/functions/assign_numbers/common.py index f00305a..c9e87bf 100644 --- a/python/problems/functions/assign_numbers/common.py +++ b/python/problems/functions/assign_numbers/common.py @@ -23,12 +23,30 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'numbers' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + ([], []), + ([1], [(0, 1)]), + ([5, 1, 4, 2, 3], [(0, 5), (1, 1), (2, 4), (3, 2), (4, 3)]), + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py index fba7570..22defeb 100644 --- a/python/problems/functions/body_mass_index/common.py +++ b/python/problems/functions/body_mass_index/common.py @@ -23,12 +23,33 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'bmi' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + ([], []), + ([('Ana', 55, 165), ('Berta', 60, 153)], + [('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]), + ([('Ana', 55, 165), ('Berta', 60, 153), ('Cilka', 70, 183)], + [('Ana', 20.202020202020204), ('Berta', 25.63116749967961), ('Cilka', 20.902385858042937)]), + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py index 58c7ab1..c94b7d1 100644 --- a/python/problems/functions/body_mass_index_2/common.py +++ b/python/problems/functions/body_mass_index_2/common.py @@ -23,12 +23,32 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'bmi2' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (([], [], []), []), + ((['Ana', 'Berta'], [55, 60], [165, 153]), + [('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]), + ((['Ana', 'Berta', 'Cilka'], [55, 60, 70], [165, 153, 183]), + [('Ana', 20.202020202020204), ('Berta', 25.63116749967961), ('Cilka', 20.902385858042937)]), + ] + + test_in = [(func_name+'(*%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/common.py b/python/problems/functions/common.py index 1367877..ede78e6 100644 --- a/python/problems/functions/common.py +++ b/python/problems/functions/common.py @@ -1 +1,2 @@ id = 17 +number = 4 \ No newline at end of file diff --git a/python/problems/functions/divisors/common.py b/python/problems/functions/divisors/common.py index c3e71d8..0b6ba0d 100644 --- a/python/problems/functions/divisors/common.py +++ b/python/problems/functions/divisors/common.py @@ -22,12 +22,36 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'divisors' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (8, [1,2,4]), + (6, [1,2,3]), + (5, [1]), + (1, []), + (2, [1]), + (15, [1,3,5]), + (20, [1,2,4,5,10]) + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + numbers = sorted(int(n) for n in get_numbers(ans[1])) + if numbers == to: + n_correct += 1 + else: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/divisors_sum/common.py b/python/problems/functions/divisors_sum/common.py index d6a2b88..256fdc3 100644 --- a/python/problems/functions/divisors_sum/common.py +++ b/python/problems/functions/divisors_sum/common.py @@ -24,12 +24,34 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'divisors_sum' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (8, 7), + (6, 6), + (5, 1), + (1, 0), + (2, 1), + (15, 9), + (20, 22) + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/friendly_numbers/common.py b/python/problems/functions/friendly_numbers/common.py index 415040e..6588242 100644 --- a/python/problems/functions/friendly_numbers/common.py +++ b/python/problems/functions/friendly_numbers/common.py @@ -18,7 +18,7 @@ def divisors_sum(n): s += i return s -def friendly_number(n): +def amicable_number(n): s = divisors_sum(n) if n == divisors_sum(s): return s @@ -29,12 +29,35 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'amicable_number' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (220, 284), + (284, 220), + (1010, None), + (6, None), + (2620, 2924), + (1, None), + (10, None), + (1210, 1184) + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/friendly_numbers/en.py b/python/problems/functions/friendly_numbers/en.py index ba740ae..c77dca1 100644 --- a/python/problems/functions/friendly_numbers/en.py +++ b/python/problems/functions/friendly_numbers/en.py @@ -1,8 +1,8 @@ # coding=utf-8 id = 233 -name = 'Friendly numbers' -slug = 'Friendly numbers' +name = 'Amicable numbers' +slug = 'Amicable numbers' description = '''\

(translation missing)

''' diff --git a/python/problems/functions/friendly_numbers/sl.py b/python/problems/functions/friendly_numbers/sl.py index d1c15ff..51d47ae 100644 --- a/python/problems/functions/friendly_numbers/sl.py +++ b/python/problems/functions/friendly_numbers/sl.py @@ -12,12 +12,12 @@ description = '''\

220 in 284 sta prijateljski števili. Delitelji 220 so 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 in 110. Če jih seštejemo, dobimo 284. Delitelji 284 pa so 1, 2, 4, 71 in 142. Vsota teh števil pa je 220. -Napiši funkcijo friendly_number(n), ki vrne prijateljsko število številu n, če ga ima, oz. +Napiši funkcijo amicable_number(n), ki vrne prijateljsko število številu n, če ga ima, oz. vrne None, če ga nima. Primer:

->>> friendly_number(220)
+>>> amicable_number(220)
 284
->>> friendly_number(222)
+>>> amicable_number(222)
 None
 

diff --git a/python/problems/functions/greatest/common.py b/python/problems/functions/greatest/common.py index 6857603..e6b7139 100644 --- a/python/problems/functions/greatest/common.py +++ b/python/problems/functions/greatest/common.py @@ -32,6 +32,10 @@ hint_type = { } def test(python, code): + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', 'max_val']): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_val'}}] + test_lists = [[6, 4, 2, 0], [4, 6, 2, 0], [4, 2, 6, 0], diff --git a/python/problems/functions/greatest_absolutist/common.py b/python/problems/functions/greatest_absolutist/common.py index 2d80097..564d0c8 100644 --- a/python/problems/functions/greatest_absolutist/common.py +++ b/python/problems/functions/greatest_absolutist/common.py @@ -35,6 +35,10 @@ hint_type = { def test(python, code): + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', 'max_abs']): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_abs'}}] + test_lists = [[6, 4, 2, 0], [4, 6, 2, 0], [4, 2, 6, 0], diff --git a/python/problems/functions/greatest_negative/common.py b/python/problems/functions/greatest_negative/common.py index 5d65438..7ab3aca 100644 --- a/python/problems/functions/greatest_negative/common.py +++ b/python/problems/functions/greatest_negative/common.py @@ -35,6 +35,10 @@ hint_type = { def test(python, code): + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', 'max_neg']): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_neg'}}] + test_lists = [[6, 4, 2, 0], [4, 6, 2, -1], [4, -2, -6, 0], diff --git a/python/problems/functions/palindrome/common.py b/python/problems/functions/palindrome/common.py index e012e8d..9bd82f4 100644 --- a/python/problems/functions/palindrome/common.py +++ b/python/problems/functions/palindrome/common.py @@ -20,12 +20,37 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'palindrome' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + ('', True), + ('a', True), + ('aa', True), + ('ab', False), + ('aba', True), + ('abc', False), + ('abcdefedcba', True), + ('abcdefgedcba', False), + ('pericarezeracirep', True), + ('perica', False), + ] + + test_in = [(func_name+'("%s")'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/palindromic_numbers/common.py b/python/problems/functions/palindromic_numbers/common.py index ba518c7..b649719 100644 --- a/python/problems/functions/palindromic_numbers/common.py +++ b/python/problems/functions/palindromic_numbers/common.py @@ -25,12 +25,34 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'numbers' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (906609, True), + (123456, False), + (1, True), + (11, True), + (12, False), + (113, False), + (131, True) + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/perfect_numbers/common.py b/python/problems/functions/perfect_numbers/common.py index ad1a7cd..64acb23 100644 --- a/python/problems/functions/perfect_numbers/common.py +++ b/python/problems/functions/perfect_numbers/common.py @@ -27,12 +27,33 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'perfect' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (6, True), + (28, True), + (1, False), + (5, False), + (496, True), + (497, False), + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + n_correct += ans[0] == to + if ans[0] != to: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) diff --git a/python/problems/functions/prime_numbers/common.py b/python/problems/functions/prime_numbers/common.py index 0447c61..6806a08 100644 --- a/python/problems/functions/prime_numbers/common.py +++ b/python/problems/functions/prime_numbers/common.py @@ -25,12 +25,33 @@ hint_type = { } def test(python, code): - test_in = [1] + func_name = 'prime' + tokens = get_tokens(code) + if not has_token_sequence(tokens, ['def', func_name]): + return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}] + + in_out = [ + (3, [2]), + (10, [2, 3, 5, 7]), + (100, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]), + ] + + test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] + test_out = [l[1] for l in in_out] + + answers = python(code=code, inputs=test_in, timeout=1.0) n_correct = 0 + tin, tout = None, None + for i, (ans, to) in enumerate(zip(answers, test_out)): + numbers = sorted([int(n) for n in get_numbers(ans[1])]) + + if numbers == to: + n_correct += 1 + else: + tin = test_in[i][0] + tout = to passed = n_correct == len(test_in) - tin = None - tout = None hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) -- cgit v1.2.1 From d43958c3b5ea7f61e772c80f63b96d8fdb61110b Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 11 Oct 2015 19:58:42 +0200 Subject: Fix ID for python/functions/body_mass_index_2 --- python/problems/functions/body_mass_index_2/common.py | 2 +- python/problems/functions/body_mass_index_2/en.py | 1 - python/problems/functions/body_mass_index_2/sl.py | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) (limited to 'python/problems/functions') diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py index c94b7d1..a88ad1c 100644 --- a/python/problems/functions/body_mass_index_2/common.py +++ b/python/problems/functions/body_mass_index_2/common.py @@ -5,7 +5,7 @@ from python.util import has_token_sequence, string_almost_equal, \ string_contains_number, get_tokens, get_numbers, get_exception_desc from server.hints import Hint -id = 226 +id = 227 group = 'functions' number = 6 visible = True diff --git a/python/problems/functions/body_mass_index_2/en.py b/python/problems/functions/body_mass_index_2/en.py index 8ce2533..b34718b 100644 --- a/python/problems/functions/body_mass_index_2/en.py +++ b/python/problems/functions/body_mass_index_2/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 226 name = 'Body mass index 2' slug = 'Body mass index 2' diff --git a/python/problems/functions/body_mass_index_2/sl.py b/python/problems/functions/body_mass_index_2/sl.py index 21e7fa0..8cd56c7 100644 --- a/python/problems/functions/body_mass_index_2/sl.py +++ b/python/problems/functions/body_mass_index_2/sl.py @@ -2,12 +2,9 @@ import server mod = server.problems.load_language('python', 'sl') - -id = 226 name = 'Indeks telesne teže 2' slug = 'Indeks telesne teže 2' - description = '''\

Naloga je podobna prejšnji, le da imamo tokrat podatke v drugačni obliki: -- cgit v1.2.1 From 6e281624b9a0ae29f1f1862f9d581b219ba3b95a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 12 Oct 2015 11:46:08 +0200 Subject: Remove group attribute from problem common.py files --- python/problems/functions/assign_numbers/common.py | 1 - python/problems/functions/body_mass_index/common.py | 1 - python/problems/functions/body_mass_index_2/common.py | 1 - python/problems/functions/divisors/common.py | 1 - python/problems/functions/divisors_sum/common.py | 1 - python/problems/functions/friendly_numbers/common.py | 1 - python/problems/functions/greatest/common.py | 1 - python/problems/functions/greatest_absolutist/common.py | 1 - python/problems/functions/greatest_negative/common.py | 1 - python/problems/functions/palindrome/common.py | 1 - python/problems/functions/palindromic_numbers/common.py | 1 - python/problems/functions/perfect_numbers/common.py | 1 - python/problems/functions/prime_numbers/common.py | 1 - 13 files changed, 13 deletions(-) (limited to 'python/problems/functions') diff --git a/python/problems/functions/assign_numbers/common.py b/python/problems/functions/assign_numbers/common.py index c9e87bf..effd061 100644 --- a/python/problems/functions/assign_numbers/common.py +++ b/python/problems/functions/assign_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 225 -group = 'lists_and_for' number = 4 visible = True diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py index 22defeb..8e774be 100644 --- a/python/problems/functions/body_mass_index/common.py +++ b/python/problems/functions/body_mass_index/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 226 -group = 'functions' number = 5 visible = True diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py index a88ad1c..c6cf2b3 100644 --- a/python/problems/functions/body_mass_index_2/common.py +++ b/python/problems/functions/body_mass_index_2/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 227 -group = 'functions' number = 6 visible = True diff --git a/python/problems/functions/divisors/common.py b/python/problems/functions/divisors/common.py index 0b6ba0d..afff7c5 100644 --- a/python/problems/functions/divisors/common.py +++ b/python/problems/functions/divisors/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 230 -group = 'functions' number = 9 visible = True diff --git a/python/problems/functions/divisors_sum/common.py b/python/problems/functions/divisors_sum/common.py index 256fdc3..142a448 100644 --- a/python/problems/functions/divisors_sum/common.py +++ b/python/problems/functions/divisors_sum/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 231 -group = 'functions' number = 10 visible = True diff --git a/python/problems/functions/friendly_numbers/common.py b/python/problems/functions/friendly_numbers/common.py index 6588242..fe121dc 100644 --- a/python/problems/functions/friendly_numbers/common.py +++ b/python/problems/functions/friendly_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 233 -group = 'functions' number = 12 visible = True diff --git a/python/problems/functions/greatest/common.py b/python/problems/functions/greatest/common.py index e6b7139..726fa88 100644 --- a/python/problems/functions/greatest/common.py +++ b/python/problems/functions/greatest/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 195 -group = 'functions' number = 1 visible = True diff --git a/python/problems/functions/greatest_absolutist/common.py b/python/problems/functions/greatest_absolutist/common.py index 564d0c8..3226b87 100644 --- a/python/problems/functions/greatest_absolutist/common.py +++ b/python/problems/functions/greatest_absolutist/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 196 -group = 'functions' number = 2 visible = True diff --git a/python/problems/functions/greatest_negative/common.py b/python/problems/functions/greatest_negative/common.py index 7ab3aca..72754e2 100644 --- a/python/problems/functions/greatest_negative/common.py +++ b/python/problems/functions/greatest_negative/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 197 -group = 'functions' number = 3 visible = True diff --git a/python/problems/functions/palindrome/common.py b/python/problems/functions/palindrome/common.py index 9bd82f4..eec8211 100644 --- a/python/problems/functions/palindrome/common.py +++ b/python/problems/functions/palindrome/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 228 -group = 'functions' number = 7 visible = True diff --git a/python/problems/functions/palindromic_numbers/common.py b/python/problems/functions/palindromic_numbers/common.py index b649719..6f49896 100644 --- a/python/problems/functions/palindromic_numbers/common.py +++ b/python/problems/functions/palindromic_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 229 -group = 'functions' number = 8 visible = True diff --git a/python/problems/functions/perfect_numbers/common.py b/python/problems/functions/perfect_numbers/common.py index 64acb23..72267e6 100644 --- a/python/problems/functions/perfect_numbers/common.py +++ b/python/problems/functions/perfect_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 232 -group = 'functions' number = 11 visible = True diff --git a/python/problems/functions/prime_numbers/common.py b/python/problems/functions/prime_numbers/common.py index 6806a08..33eb134 100644 --- a/python/problems/functions/prime_numbers/common.py +++ b/python/problems/functions/prime_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 234 -group = 'functions' number = 13 visible = True -- cgit v1.2.1