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