1import string
2from inspect import getmembers, isfunction, ismethod
3
4import secret
5
6
7class FunctionTester:
8 def _is_specific_exception_function(
9 self, function, exception_type, exception_message=None
10 ):
11 try:
12 function()
13 except exception_type as exception:
14 is_correct_type = type(exception) is exception_type
15 if exception_message:
16 return is_correct_type and str(exception) == exception_message
17
18 return is_correct_type
19 except BaseException:
20 return False
21
22 return False
23
24 @staticmethod
25 def _exception_guard(function):
26 def wrapper(*args, **kwargs):
27 try:
28 return function(*args, **kwargs)
29 except BaseException:
30 return False
31
32 return wrapper
33
34 @_exception_guard
35 def _is_same_as_function(self, function, stub_function, test_cases):
36 for args in test_cases:
37 if function(*args) != stub_function(*args):
38 return False
39 return True
40
41
42class ChallengeFunctionTester(FunctionTester):
43 def is_type_error_function(self, function):
44 type_error_message = "Опаааааа, тука има нещо нередно."
45 return self._is_specific_exception_function(
46 function, TypeError, type_error_message
47 )
48
49 def is_base_error_function(self, function):
50 return self._is_specific_exception_function(function, BaseException)
51
52 def is_int_function(self, function):
53 def int_function_stub(x):
54 return x**2 if x % 2 == 0 else 0
55
56 int_test_range = 100
57
58 test_cases = [
59 (el,) for el in range(-int_test_range, int_test_range + 1)
60 ]
61
62 return self._is_same_as_function(
63 function, int_function_stub, test_cases
64 )
65
66 def is_string_function(self, function):
67 def string_function_stub(left, right):
68 return left + right
69
70 string_test_cases = [
71 ("a", "b"),
72 ("abc", "123"),
73 ("XxX", ""),
74 ("", "YyY"),
75 ("", ""),
76 ]
77 return self._is_same_as_function(
78 function, string_function_stub, string_test_cases
79 )
80
81 def is_static_function(self, function):
82 """Not ideal"""
83 return not ismethod(function) and function not in [
84 function for _, function in getmembers(secret)
85 ]
86
87 def is_function_name_ok(self, function):
88 allowed_characters = list(string.ascii_uppercase + string.digits)
89 return function.__name__ in allowed_characters
90
91 def is_interesting(self, function):
92 if not self.is_function_name_ok(function):
93 return False
94
95 checkers = [
96 self.is_type_error_function,
97 self.is_base_error_function,
98 self.is_int_function,
99 self.is_string_function,
100 self.is_static_function,
101 ]
102
103 return any(checker(function) for checker in checkers)
104
105
106def list_all_functions(module_name, member_keyword):
107 stack = [module_name]
108 functions = []
109
110 while stack:
111 current = stack.pop()
112
113 members = getmembers(current)
114 functions.extend([value for _, value in members if isfunction(value)])
115
116 stack.extend(
117 [value for name, value in members if member_keyword in name]
118 )
119
120 return functions
121
122
123def get_interesting_functions():
124 member_keyword = "clue"
125
126 functions = list_all_functions(secret, member_keyword)
127 function_tester = ChallengeFunctionTester()
128
129 return [
130 function
131 for function in functions
132 if function_tester.is_interesting(function)
133 ]
134
135
136def methodify():
137 faculty_number = "FN4MI0600097"
138 interesting_functions = set(get_interesting_functions())
139
140 functions_by_name = {
141 function.__name__: function for function in interesting_functions
142 }
143 fn_functions = [functions_by_name[letter] for letter in faculty_number]
144
145 return tuple(fn_functions)
E
======================================================================
ERROR: test_metodify (test.TestMethodify)
Test metodify function.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 12, in test_metodify
self.assertIn(methodify(), _RESULTS.keys())
File "/tmp/solution.py", line 143, in methodify
fn_functions = [functions_by_name[letter] for letter in faculty_number]
File "/tmp/solution.py", line 143, in <listcomp>
fn_functions = [functions_by_name[letter] for letter in faculty_number]
KeyError: 'F'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Георги Кунчев
19.11.2023 00:04Няма да сме гадни. Подай число и виж дали вдига на квадрат или е нула. Няма функции, които изглеждат като дефинициите ни, но само понякога.
|
Теодор Костадинов
18.11.2023 22:24Как се очаква прецизно да сравняваме функциите за int/ string? Например, функция от сорта на ```return x**2 if x % 2 == 0 and x != 4_000_000 else 0``` би била некоректна, но трудно ще се хване.
Или нещо друго бъркам...
|
f | 1 | import string | f | 1 | import string |
2 | from inspect import getmembers, isfunction, ismethod | 2 | from inspect import getmembers, isfunction, ismethod | ||
3 | 3 | ||||
4 | import secret | 4 | import secret | ||
5 | 5 | ||||
6 | 6 | ||||
7 | class FunctionTester: | 7 | class FunctionTester: | ||
8 | def _is_specific_exception_function( | 8 | def _is_specific_exception_function( | ||
9 | self, function, exception_type, exception_message=None | 9 | self, function, exception_type, exception_message=None | ||
10 | ): | 10 | ): | ||
11 | try: | 11 | try: | ||
12 | function() | 12 | function() | ||
13 | except exception_type as exception: | 13 | except exception_type as exception: | ||
14 | is_correct_type = type(exception) is exception_type | 14 | is_correct_type = type(exception) is exception_type | ||
15 | if exception_message: | 15 | if exception_message: | ||
16 | return is_correct_type and str(exception) == exception_message | 16 | return is_correct_type and str(exception) == exception_message | ||
17 | 17 | ||||
18 | return is_correct_type | 18 | return is_correct_type | ||
19 | except BaseException: | 19 | except BaseException: | ||
20 | return False | 20 | return False | ||
21 | 21 | ||||
22 | return False | 22 | return False | ||
23 | 23 | ||||
24 | @staticmethod | 24 | @staticmethod | ||
25 | def _exception_guard(function): | 25 | def _exception_guard(function): | ||
26 | def wrapper(*args, **kwargs): | 26 | def wrapper(*args, **kwargs): | ||
27 | try: | 27 | try: | ||
28 | return function(*args, **kwargs) | 28 | return function(*args, **kwargs) | ||
29 | except BaseException: | 29 | except BaseException: | ||
30 | return False | 30 | return False | ||
31 | 31 | ||||
32 | return wrapper | 32 | return wrapper | ||
33 | 33 | ||||
34 | @_exception_guard | 34 | @_exception_guard | ||
35 | def _is_same_as_function(self, function, stub_function, test_cases): | 35 | def _is_same_as_function(self, function, stub_function, test_cases): | ||
36 | for args in test_cases: | 36 | for args in test_cases: | ||
37 | if function(*args) != stub_function(*args): | 37 | if function(*args) != stub_function(*args): | ||
38 | return False | 38 | return False | ||
39 | return True | 39 | return True | ||
40 | 40 | ||||
41 | 41 | ||||
42 | class ChallengeFunctionTester(FunctionTester): | 42 | class ChallengeFunctionTester(FunctionTester): | ||
43 | def is_type_error_function(self, function): | 43 | def is_type_error_function(self, function): | ||
44 | type_error_message = "Опаааааа, тука има нещо нередно." | 44 | type_error_message = "Опаааааа, тука има нещо нередно." | ||
45 | return self._is_specific_exception_function( | 45 | return self._is_specific_exception_function( | ||
46 | function, TypeError, type_error_message | 46 | function, TypeError, type_error_message | ||
47 | ) | 47 | ) | ||
48 | 48 | ||||
49 | def is_base_error_function(self, function): | 49 | def is_base_error_function(self, function): | ||
50 | return self._is_specific_exception_function(function, BaseException) | 50 | return self._is_specific_exception_function(function, BaseException) | ||
51 | 51 | ||||
52 | def is_int_function(self, function): | 52 | def is_int_function(self, function): | ||
53 | def int_function_stub(x): | 53 | def int_function_stub(x): | ||
54 | return x**2 if x % 2 == 0 else 0 | 54 | return x**2 if x % 2 == 0 else 0 | ||
55 | 55 | ||||
56 | int_test_range = 100 | 56 | int_test_range = 100 | ||
57 | 57 | ||||
58 | test_cases = [ | 58 | test_cases = [ | ||
59 | (el,) for el in range(-int_test_range, int_test_range + 1) | 59 | (el,) for el in range(-int_test_range, int_test_range + 1) | ||
60 | ] | 60 | ] | ||
61 | 61 | ||||
62 | return self._is_same_as_function( | 62 | return self._is_same_as_function( | ||
63 | function, int_function_stub, test_cases | 63 | function, int_function_stub, test_cases | ||
64 | ) | 64 | ) | ||
65 | 65 | ||||
66 | def is_string_function(self, function): | 66 | def is_string_function(self, function): | ||
67 | def string_function_stub(left, right): | 67 | def string_function_stub(left, right): | ||
68 | return left + right | 68 | return left + right | ||
69 | 69 | ||||
70 | string_test_cases = [ | 70 | string_test_cases = [ | ||
71 | ("a", "b"), | 71 | ("a", "b"), | ||
72 | ("abc", "123"), | 72 | ("abc", "123"), | ||
73 | ("XxX", ""), | 73 | ("XxX", ""), | ||
74 | ("", "YyY"), | 74 | ("", "YyY"), | ||
75 | ("", ""), | 75 | ("", ""), | ||
76 | ] | 76 | ] | ||
77 | return self._is_same_as_function( | 77 | return self._is_same_as_function( | ||
78 | function, string_function_stub, string_test_cases | 78 | function, string_function_stub, string_test_cases | ||
79 | ) | 79 | ) | ||
80 | 80 | ||||
81 | def is_static_function(self, function): | 81 | def is_static_function(self, function): | ||
t | 82 | return isfunction(function) and not ismethod(function) | t | 82 | """Not ideal""" |
83 | return not ismethod(function) and function not in [ | ||||
84 | function for _, function in getmembers(secret) | ||||
85 | ] | ||||
83 | 86 | ||||
84 | def is_function_name_ok(self, function): | 87 | def is_function_name_ok(self, function): | ||
85 | allowed_characters = list(string.ascii_uppercase + string.digits) | 88 | allowed_characters = list(string.ascii_uppercase + string.digits) | ||
86 | return function.__name__ in allowed_characters | 89 | return function.__name__ in allowed_characters | ||
87 | 90 | ||||
88 | def is_interesting(self, function): | 91 | def is_interesting(self, function): | ||
89 | if not self.is_function_name_ok(function): | 92 | if not self.is_function_name_ok(function): | ||
90 | return False | 93 | return False | ||
91 | 94 | ||||
92 | checkers = [ | 95 | checkers = [ | ||
93 | self.is_type_error_function, | 96 | self.is_type_error_function, | ||
94 | self.is_base_error_function, | 97 | self.is_base_error_function, | ||
95 | self.is_int_function, | 98 | self.is_int_function, | ||
96 | self.is_string_function, | 99 | self.is_string_function, | ||
97 | self.is_static_function, | 100 | self.is_static_function, | ||
98 | ] | 101 | ] | ||
99 | 102 | ||||
100 | return any(checker(function) for checker in checkers) | 103 | return any(checker(function) for checker in checkers) | ||
101 | 104 | ||||
102 | 105 | ||||
103 | def list_all_functions(module_name, member_keyword): | 106 | def list_all_functions(module_name, member_keyword): | ||
104 | stack = [module_name] | 107 | stack = [module_name] | ||
105 | functions = [] | 108 | functions = [] | ||
106 | 109 | ||||
107 | while stack: | 110 | while stack: | ||
108 | current = stack.pop() | 111 | current = stack.pop() | ||
109 | 112 | ||||
110 | members = getmembers(current) | 113 | members = getmembers(current) | ||
111 | functions.extend([value for _, value in members if isfunction(value)]) | 114 | functions.extend([value for _, value in members if isfunction(value)]) | ||
112 | 115 | ||||
113 | stack.extend( | 116 | stack.extend( | ||
114 | [value for name, value in members if member_keyword in name] | 117 | [value for name, value in members if member_keyword in name] | ||
115 | ) | 118 | ) | ||
116 | 119 | ||||
117 | return functions | 120 | return functions | ||
118 | 121 | ||||
119 | 122 | ||||
120 | def get_interesting_functions(): | 123 | def get_interesting_functions(): | ||
121 | member_keyword = "clue" | 124 | member_keyword = "clue" | ||
122 | 125 | ||||
123 | functions = list_all_functions(secret, member_keyword) | 126 | functions = list_all_functions(secret, member_keyword) | ||
124 | function_tester = ChallengeFunctionTester() | 127 | function_tester = ChallengeFunctionTester() | ||
125 | 128 | ||||
126 | return [ | 129 | return [ | ||
127 | function | 130 | function | ||
128 | for function in functions | 131 | for function in functions | ||
129 | if function_tester.is_interesting(function) | 132 | if function_tester.is_interesting(function) | ||
130 | ] | 133 | ] | ||
131 | 134 | ||||
132 | 135 | ||||
133 | def methodify(): | 136 | def methodify(): | ||
134 | faculty_number = "FN4MI0600097" | 137 | faculty_number = "FN4MI0600097" | ||
135 | interesting_functions = set(get_interesting_functions()) | 138 | interesting_functions = set(get_interesting_functions()) | ||
136 | 139 | ||||
137 | functions_by_name = { | 140 | functions_by_name = { | ||
138 | function.__name__: function for function in interesting_functions | 141 | function.__name__: function for function in interesting_functions | ||
139 | } | 142 | } | ||
140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | 143 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | ||
141 | 144 | ||||
142 | return tuple(fn_functions) | 145 | return tuple(fn_functions) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import string | f | 1 | import string |
n | 2 | from inspect import getmembers, isfunction | n | 2 | from inspect import getmembers, isfunction, ismethod |
3 | 3 | ||||
4 | import secret | 4 | import secret | ||
5 | 5 | ||||
6 | 6 | ||||
7 | class FunctionTester: | 7 | class FunctionTester: | ||
8 | def _is_specific_exception_function( | 8 | def _is_specific_exception_function( | ||
9 | self, function, exception_type, exception_message=None | 9 | self, function, exception_type, exception_message=None | ||
10 | ): | 10 | ): | ||
11 | try: | 11 | try: | ||
12 | function() | 12 | function() | ||
13 | except exception_type as exception: | 13 | except exception_type as exception: | ||
14 | is_correct_type = type(exception) is exception_type | 14 | is_correct_type = type(exception) is exception_type | ||
15 | if exception_message: | 15 | if exception_message: | ||
16 | return is_correct_type and str(exception) == exception_message | 16 | return is_correct_type and str(exception) == exception_message | ||
17 | 17 | ||||
18 | return is_correct_type | 18 | return is_correct_type | ||
19 | except BaseException: | 19 | except BaseException: | ||
20 | return False | 20 | return False | ||
21 | 21 | ||||
22 | return False | 22 | return False | ||
23 | 23 | ||||
24 | @staticmethod | 24 | @staticmethod | ||
25 | def _exception_guard(function): | 25 | def _exception_guard(function): | ||
26 | def wrapper(*args, **kwargs): | 26 | def wrapper(*args, **kwargs): | ||
27 | try: | 27 | try: | ||
28 | return function(*args, **kwargs) | 28 | return function(*args, **kwargs) | ||
29 | except BaseException: | 29 | except BaseException: | ||
30 | return False | 30 | return False | ||
31 | 31 | ||||
32 | return wrapper | 32 | return wrapper | ||
33 | 33 | ||||
34 | @_exception_guard | 34 | @_exception_guard | ||
35 | def _is_same_as_function(self, function, stub_function, test_cases): | 35 | def _is_same_as_function(self, function, stub_function, test_cases): | ||
36 | for args in test_cases: | 36 | for args in test_cases: | ||
37 | if function(*args) != stub_function(*args): | 37 | if function(*args) != stub_function(*args): | ||
38 | return False | 38 | return False | ||
39 | return True | 39 | return True | ||
40 | 40 | ||||
41 | 41 | ||||
42 | class ChallengeFunctionTester(FunctionTester): | 42 | class ChallengeFunctionTester(FunctionTester): | ||
43 | def is_type_error_function(self, function): | 43 | def is_type_error_function(self, function): | ||
44 | type_error_message = "Опаааааа, тука има нещо нередно." | 44 | type_error_message = "Опаааааа, тука има нещо нередно." | ||
45 | return self._is_specific_exception_function( | 45 | return self._is_specific_exception_function( | ||
46 | function, TypeError, type_error_message | 46 | function, TypeError, type_error_message | ||
47 | ) | 47 | ) | ||
48 | 48 | ||||
49 | def is_base_error_function(self, function): | 49 | def is_base_error_function(self, function): | ||
50 | return self._is_specific_exception_function(function, BaseException) | 50 | return self._is_specific_exception_function(function, BaseException) | ||
51 | 51 | ||||
52 | def is_int_function(self, function): | 52 | def is_int_function(self, function): | ||
53 | def int_function_stub(x): | 53 | def int_function_stub(x): | ||
54 | return x**2 if x % 2 == 0 else 0 | 54 | return x**2 if x % 2 == 0 else 0 | ||
55 | 55 | ||||
56 | int_test_range = 100 | 56 | int_test_range = 100 | ||
57 | 57 | ||||
58 | test_cases = [ | 58 | test_cases = [ | ||
59 | (el,) for el in range(-int_test_range, int_test_range + 1) | 59 | (el,) for el in range(-int_test_range, int_test_range + 1) | ||
60 | ] | 60 | ] | ||
61 | 61 | ||||
62 | return self._is_same_as_function( | 62 | return self._is_same_as_function( | ||
63 | function, int_function_stub, test_cases | 63 | function, int_function_stub, test_cases | ||
64 | ) | 64 | ) | ||
65 | 65 | ||||
66 | def is_string_function(self, function): | 66 | def is_string_function(self, function): | ||
67 | def string_function_stub(left, right): | 67 | def string_function_stub(left, right): | ||
68 | return left + right | 68 | return left + right | ||
69 | 69 | ||||
70 | string_test_cases = [ | 70 | string_test_cases = [ | ||
71 | ("a", "b"), | 71 | ("a", "b"), | ||
72 | ("abc", "123"), | 72 | ("abc", "123"), | ||
73 | ("XxX", ""), | 73 | ("XxX", ""), | ||
74 | ("", "YyY"), | 74 | ("", "YyY"), | ||
75 | ("", ""), | 75 | ("", ""), | ||
76 | ] | 76 | ] | ||
77 | return self._is_same_as_function( | 77 | return self._is_same_as_function( | ||
78 | function, string_function_stub, string_test_cases | 78 | function, string_function_stub, string_test_cases | ||
79 | ) | 79 | ) | ||
80 | 80 | ||||
81 | def is_static_function(self, function): | 81 | def is_static_function(self, function): | ||
n | 82 | return False | n | 82 | return isfunction(function) and not ismethod(function) |
83 | 83 | ||||
84 | def is_function_name_ok(self, function): | 84 | def is_function_name_ok(self, function): | ||
85 | allowed_characters = list(string.ascii_uppercase + string.digits) | 85 | allowed_characters = list(string.ascii_uppercase + string.digits) | ||
86 | return function.__name__ in allowed_characters | 86 | return function.__name__ in allowed_characters | ||
87 | 87 | ||||
88 | def is_interesting(self, function): | 88 | def is_interesting(self, function): | ||
89 | if not self.is_function_name_ok(function): | 89 | if not self.is_function_name_ok(function): | ||
90 | return False | 90 | return False | ||
91 | 91 | ||||
92 | checkers = [ | 92 | checkers = [ | ||
93 | self.is_type_error_function, | 93 | self.is_type_error_function, | ||
94 | self.is_base_error_function, | 94 | self.is_base_error_function, | ||
95 | self.is_int_function, | 95 | self.is_int_function, | ||
96 | self.is_string_function, | 96 | self.is_string_function, | ||
97 | self.is_static_function, | 97 | self.is_static_function, | ||
98 | ] | 98 | ] | ||
99 | 99 | ||||
100 | return any(checker(function) for checker in checkers) | 100 | return any(checker(function) for checker in checkers) | ||
101 | 101 | ||||
102 | 102 | ||||
103 | def list_all_functions(module_name, member_keyword): | 103 | def list_all_functions(module_name, member_keyword): | ||
104 | stack = [module_name] | 104 | stack = [module_name] | ||
105 | functions = [] | 105 | functions = [] | ||
106 | 106 | ||||
107 | while stack: | 107 | while stack: | ||
108 | current = stack.pop() | 108 | current = stack.pop() | ||
109 | 109 | ||||
110 | members = getmembers(current) | 110 | members = getmembers(current) | ||
111 | functions.extend([value for _, value in members if isfunction(value)]) | 111 | functions.extend([value for _, value in members if isfunction(value)]) | ||
112 | 112 | ||||
113 | stack.extend( | 113 | stack.extend( | ||
114 | [value for name, value in members if member_keyword in name] | 114 | [value for name, value in members if member_keyword in name] | ||
115 | ) | 115 | ) | ||
116 | 116 | ||||
117 | return functions | 117 | return functions | ||
118 | 118 | ||||
119 | 119 | ||||
120 | def get_interesting_functions(): | 120 | def get_interesting_functions(): | ||
121 | member_keyword = "clue" | 121 | member_keyword = "clue" | ||
122 | 122 | ||||
123 | functions = list_all_functions(secret, member_keyword) | 123 | functions = list_all_functions(secret, member_keyword) | ||
124 | function_tester = ChallengeFunctionTester() | 124 | function_tester = ChallengeFunctionTester() | ||
125 | 125 | ||||
126 | return [ | 126 | return [ | ||
127 | function | 127 | function | ||
128 | for function in functions | 128 | for function in functions | ||
129 | if function_tester.is_interesting(function) | 129 | if function_tester.is_interesting(function) | ||
130 | ] | 130 | ] | ||
131 | 131 | ||||
132 | 132 | ||||
133 | def methodify(): | 133 | def methodify(): | ||
134 | faculty_number = "FN4MI0600097" | 134 | faculty_number = "FN4MI0600097" | ||
n | 135 | interesting_functions = get_interesting_functions() | n | 135 | interesting_functions = set(get_interesting_functions()) |
136 | 136 | ||||
137 | functions_by_name = { | 137 | functions_by_name = { | ||
138 | function.__name__: function for function in interesting_functions | 138 | function.__name__: function for function in interesting_functions | ||
139 | } | 139 | } | ||
140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | 140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | ||
141 | 141 | ||||
142 | return tuple(fn_functions) | 142 | return tuple(fn_functions) | ||
t | 143 | t |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import string | f | 1 | import string |
2 | from inspect import getmembers, isfunction | 2 | from inspect import getmembers, isfunction | ||
3 | 3 | ||||
4 | import secret | 4 | import secret | ||
5 | 5 | ||||
6 | 6 | ||||
7 | class FunctionTester: | 7 | class FunctionTester: | ||
8 | def _is_specific_exception_function( | 8 | def _is_specific_exception_function( | ||
9 | self, function, exception_type, exception_message=None | 9 | self, function, exception_type, exception_message=None | ||
10 | ): | 10 | ): | ||
11 | try: | 11 | try: | ||
12 | function() | 12 | function() | ||
13 | except exception_type as exception: | 13 | except exception_type as exception: | ||
14 | is_correct_type = type(exception) is exception_type | 14 | is_correct_type = type(exception) is exception_type | ||
15 | if exception_message: | 15 | if exception_message: | ||
16 | return is_correct_type and str(exception) == exception_message | 16 | return is_correct_type and str(exception) == exception_message | ||
17 | 17 | ||||
18 | return is_correct_type | 18 | return is_correct_type | ||
19 | except BaseException: | 19 | except BaseException: | ||
20 | return False | 20 | return False | ||
21 | 21 | ||||
22 | return False | 22 | return False | ||
23 | 23 | ||||
24 | @staticmethod | 24 | @staticmethod | ||
25 | def _exception_guard(function): | 25 | def _exception_guard(function): | ||
26 | def wrapper(*args, **kwargs): | 26 | def wrapper(*args, **kwargs): | ||
27 | try: | 27 | try: | ||
28 | return function(*args, **kwargs) | 28 | return function(*args, **kwargs) | ||
29 | except BaseException: | 29 | except BaseException: | ||
30 | return False | 30 | return False | ||
31 | 31 | ||||
32 | return wrapper | 32 | return wrapper | ||
33 | 33 | ||||
34 | @_exception_guard | 34 | @_exception_guard | ||
35 | def _is_same_as_function(self, function, stub_function, test_cases): | 35 | def _is_same_as_function(self, function, stub_function, test_cases): | ||
36 | for args in test_cases: | 36 | for args in test_cases: | ||
37 | if function(*args) != stub_function(*args): | 37 | if function(*args) != stub_function(*args): | ||
38 | return False | 38 | return False | ||
39 | return True | 39 | return True | ||
40 | 40 | ||||
41 | 41 | ||||
42 | class ChallengeFunctionTester(FunctionTester): | 42 | class ChallengeFunctionTester(FunctionTester): | ||
43 | def is_type_error_function(self, function): | 43 | def is_type_error_function(self, function): | ||
44 | type_error_message = "Опаааааа, тука има нещо нередно." | 44 | type_error_message = "Опаааааа, тука има нещо нередно." | ||
45 | return self._is_specific_exception_function( | 45 | return self._is_specific_exception_function( | ||
46 | function, TypeError, type_error_message | 46 | function, TypeError, type_error_message | ||
47 | ) | 47 | ) | ||
48 | 48 | ||||
49 | def is_base_error_function(self, function): | 49 | def is_base_error_function(self, function): | ||
50 | return self._is_specific_exception_function(function, BaseException) | 50 | return self._is_specific_exception_function(function, BaseException) | ||
51 | 51 | ||||
52 | def is_int_function(self, function): | 52 | def is_int_function(self, function): | ||
53 | def int_function_stub(x): | 53 | def int_function_stub(x): | ||
54 | return x**2 if x % 2 == 0 else 0 | 54 | return x**2 if x % 2 == 0 else 0 | ||
55 | 55 | ||||
56 | int_test_range = 100 | 56 | int_test_range = 100 | ||
57 | 57 | ||||
58 | test_cases = [ | 58 | test_cases = [ | ||
59 | (el,) for el in range(-int_test_range, int_test_range + 1) | 59 | (el,) for el in range(-int_test_range, int_test_range + 1) | ||
60 | ] | 60 | ] | ||
61 | 61 | ||||
62 | return self._is_same_as_function( | 62 | return self._is_same_as_function( | ||
63 | function, int_function_stub, test_cases | 63 | function, int_function_stub, test_cases | ||
64 | ) | 64 | ) | ||
65 | 65 | ||||
66 | def is_string_function(self, function): | 66 | def is_string_function(self, function): | ||
67 | def string_function_stub(left, right): | 67 | def string_function_stub(left, right): | ||
68 | return left + right | 68 | return left + right | ||
69 | 69 | ||||
70 | string_test_cases = [ | 70 | string_test_cases = [ | ||
71 | ("a", "b"), | 71 | ("a", "b"), | ||
72 | ("abc", "123"), | 72 | ("abc", "123"), | ||
73 | ("XxX", ""), | 73 | ("XxX", ""), | ||
74 | ("", "YyY"), | 74 | ("", "YyY"), | ||
75 | ("", ""), | 75 | ("", ""), | ||
76 | ] | 76 | ] | ||
77 | return self._is_same_as_function( | 77 | return self._is_same_as_function( | ||
78 | function, string_function_stub, string_test_cases | 78 | function, string_function_stub, string_test_cases | ||
79 | ) | 79 | ) | ||
80 | 80 | ||||
81 | def is_static_function(self, function): | 81 | def is_static_function(self, function): | ||
82 | return False | 82 | return False | ||
83 | 83 | ||||
84 | def is_function_name_ok(self, function): | 84 | def is_function_name_ok(self, function): | ||
85 | allowed_characters = list(string.ascii_uppercase + string.digits) | 85 | allowed_characters = list(string.ascii_uppercase + string.digits) | ||
86 | return function.__name__ in allowed_characters | 86 | return function.__name__ in allowed_characters | ||
87 | 87 | ||||
88 | def is_interesting(self, function): | 88 | def is_interesting(self, function): | ||
89 | if not self.is_function_name_ok(function): | 89 | if not self.is_function_name_ok(function): | ||
90 | return False | 90 | return False | ||
91 | 91 | ||||
92 | checkers = [ | 92 | checkers = [ | ||
93 | self.is_type_error_function, | 93 | self.is_type_error_function, | ||
94 | self.is_base_error_function, | 94 | self.is_base_error_function, | ||
95 | self.is_int_function, | 95 | self.is_int_function, | ||
96 | self.is_string_function, | 96 | self.is_string_function, | ||
97 | self.is_static_function, | 97 | self.is_static_function, | ||
98 | ] | 98 | ] | ||
99 | 99 | ||||
100 | return any(checker(function) for checker in checkers) | 100 | return any(checker(function) for checker in checkers) | ||
101 | 101 | ||||
102 | 102 | ||||
103 | def list_all_functions(module_name, member_keyword): | 103 | def list_all_functions(module_name, member_keyword): | ||
104 | stack = [module_name] | 104 | stack = [module_name] | ||
105 | functions = [] | 105 | functions = [] | ||
106 | 106 | ||||
107 | while stack: | 107 | while stack: | ||
108 | current = stack.pop() | 108 | current = stack.pop() | ||
109 | 109 | ||||
110 | members = getmembers(current) | 110 | members = getmembers(current) | ||
111 | functions.extend([value for _, value in members if isfunction(value)]) | 111 | functions.extend([value for _, value in members if isfunction(value)]) | ||
112 | 112 | ||||
113 | stack.extend( | 113 | stack.extend( | ||
114 | [value for name, value in members if member_keyword in name] | 114 | [value for name, value in members if member_keyword in name] | ||
115 | ) | 115 | ) | ||
116 | 116 | ||||
117 | return functions | 117 | return functions | ||
118 | 118 | ||||
119 | 119 | ||||
120 | def get_interesting_functions(): | 120 | def get_interesting_functions(): | ||
121 | member_keyword = "clue" | 121 | member_keyword = "clue" | ||
122 | 122 | ||||
123 | functions = list_all_functions(secret, member_keyword) | 123 | functions = list_all_functions(secret, member_keyword) | ||
124 | function_tester = ChallengeFunctionTester() | 124 | function_tester = ChallengeFunctionTester() | ||
125 | 125 | ||||
126 | return [ | 126 | return [ | ||
127 | function | 127 | function | ||
128 | for function in functions | 128 | for function in functions | ||
129 | if function_tester.is_interesting(function) | 129 | if function_tester.is_interesting(function) | ||
130 | ] | 130 | ] | ||
131 | 131 | ||||
132 | 132 | ||||
133 | def methodify(): | 133 | def methodify(): | ||
t | 134 | faculty_number = "4MI0600097" | t | 134 | faculty_number = "FN4MI0600097" |
135 | interesting_functions = get_interesting_functions() | 135 | interesting_functions = get_interesting_functions() | ||
136 | 136 | ||||
137 | functions_by_name = { | 137 | functions_by_name = { | ||
138 | function.__name__: function for function in interesting_functions | 138 | function.__name__: function for function in interesting_functions | ||
139 | } | 139 | } | ||
140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | 140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | ||
141 | 141 | ||||
142 | return tuple(fn_functions) | 142 | return tuple(fn_functions) | ||
143 | 143 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import string | f | 1 | import string |
2 | from inspect import getmembers, isfunction | 2 | from inspect import getmembers, isfunction | ||
3 | 3 | ||||
4 | import secret | 4 | import secret | ||
5 | 5 | ||||
6 | 6 | ||||
7 | class FunctionTester: | 7 | class FunctionTester: | ||
8 | def _is_specific_exception_function( | 8 | def _is_specific_exception_function( | ||
9 | self, function, exception_type, exception_message=None | 9 | self, function, exception_type, exception_message=None | ||
10 | ): | 10 | ): | ||
11 | try: | 11 | try: | ||
12 | function() | 12 | function() | ||
13 | except exception_type as exception: | 13 | except exception_type as exception: | ||
14 | is_correct_type = type(exception) is exception_type | 14 | is_correct_type = type(exception) is exception_type | ||
15 | if exception_message: | 15 | if exception_message: | ||
16 | return is_correct_type and str(exception) == exception_message | 16 | return is_correct_type and str(exception) == exception_message | ||
17 | 17 | ||||
18 | return is_correct_type | 18 | return is_correct_type | ||
19 | except BaseException: | 19 | except BaseException: | ||
20 | return False | 20 | return False | ||
21 | 21 | ||||
22 | return False | 22 | return False | ||
23 | 23 | ||||
24 | @staticmethod | 24 | @staticmethod | ||
25 | def _exception_guard(function): | 25 | def _exception_guard(function): | ||
26 | def wrapper(*args, **kwargs): | 26 | def wrapper(*args, **kwargs): | ||
27 | try: | 27 | try: | ||
28 | return function(*args, **kwargs) | 28 | return function(*args, **kwargs) | ||
29 | except BaseException: | 29 | except BaseException: | ||
30 | return False | 30 | return False | ||
31 | 31 | ||||
32 | return wrapper | 32 | return wrapper | ||
33 | 33 | ||||
34 | @_exception_guard | 34 | @_exception_guard | ||
35 | def _is_same_as_function(self, function, stub_function, test_cases): | 35 | def _is_same_as_function(self, function, stub_function, test_cases): | ||
36 | for args in test_cases: | 36 | for args in test_cases: | ||
37 | if function(*args) != stub_function(*args): | 37 | if function(*args) != stub_function(*args): | ||
38 | return False | 38 | return False | ||
39 | return True | 39 | return True | ||
40 | 40 | ||||
41 | 41 | ||||
42 | class ChallengeFunctionTester(FunctionTester): | 42 | class ChallengeFunctionTester(FunctionTester): | ||
43 | def is_type_error_function(self, function): | 43 | def is_type_error_function(self, function): | ||
44 | type_error_message = "Опаааааа, тука има нещо нередно." | 44 | type_error_message = "Опаааааа, тука има нещо нередно." | ||
45 | return self._is_specific_exception_function( | 45 | return self._is_specific_exception_function( | ||
46 | function, TypeError, type_error_message | 46 | function, TypeError, type_error_message | ||
47 | ) | 47 | ) | ||
48 | 48 | ||||
49 | def is_base_error_function(self, function): | 49 | def is_base_error_function(self, function): | ||
50 | return self._is_specific_exception_function(function, BaseException) | 50 | return self._is_specific_exception_function(function, BaseException) | ||
51 | 51 | ||||
52 | def is_int_function(self, function): | 52 | def is_int_function(self, function): | ||
53 | def int_function_stub(x): | 53 | def int_function_stub(x): | ||
54 | return x**2 if x % 2 == 0 else 0 | 54 | return x**2 if x % 2 == 0 else 0 | ||
55 | 55 | ||||
56 | int_test_range = 100 | 56 | int_test_range = 100 | ||
57 | 57 | ||||
58 | test_cases = [ | 58 | test_cases = [ | ||
59 | (el,) for el in range(-int_test_range, int_test_range + 1) | 59 | (el,) for el in range(-int_test_range, int_test_range + 1) | ||
60 | ] | 60 | ] | ||
61 | 61 | ||||
62 | return self._is_same_as_function( | 62 | return self._is_same_as_function( | ||
63 | function, int_function_stub, test_cases | 63 | function, int_function_stub, test_cases | ||
64 | ) | 64 | ) | ||
65 | 65 | ||||
66 | def is_string_function(self, function): | 66 | def is_string_function(self, function): | ||
n | 67 | def _string_function_stub(left, right): | n | 67 | def string_function_stub(left, right): |
68 | return left + right | 68 | return left + right | ||
69 | 69 | ||||
70 | string_test_cases = [ | 70 | string_test_cases = [ | ||
71 | ("a", "b"), | 71 | ("a", "b"), | ||
72 | ("abc", "123"), | 72 | ("abc", "123"), | ||
73 | ("XxX", ""), | 73 | ("XxX", ""), | ||
74 | ("", "YyY"), | 74 | ("", "YyY"), | ||
75 | ("", ""), | 75 | ("", ""), | ||
76 | ] | 76 | ] | ||
77 | return self._is_same_as_function( | 77 | return self._is_same_as_function( | ||
n | 78 | function, _string_function_stub, string_test_cases | n | 78 | function, string_function_stub, string_test_cases |
79 | ) | 79 | ) | ||
80 | 80 | ||||
81 | def is_static_function(self, function): | 81 | def is_static_function(self, function): | ||
82 | return False | 82 | return False | ||
83 | 83 | ||||
84 | def is_function_name_ok(self, function): | 84 | def is_function_name_ok(self, function): | ||
85 | allowed_characters = list(string.ascii_uppercase + string.digits) | 85 | allowed_characters = list(string.ascii_uppercase + string.digits) | ||
86 | return function.__name__ in allowed_characters | 86 | return function.__name__ in allowed_characters | ||
87 | 87 | ||||
88 | def is_interesting(self, function): | 88 | def is_interesting(self, function): | ||
89 | if not self.is_function_name_ok(function): | 89 | if not self.is_function_name_ok(function): | ||
90 | return False | 90 | return False | ||
91 | 91 | ||||
92 | checkers = [ | 92 | checkers = [ | ||
93 | self.is_type_error_function, | 93 | self.is_type_error_function, | ||
94 | self.is_base_error_function, | 94 | self.is_base_error_function, | ||
95 | self.is_int_function, | 95 | self.is_int_function, | ||
96 | self.is_string_function, | 96 | self.is_string_function, | ||
97 | self.is_static_function, | 97 | self.is_static_function, | ||
98 | ] | 98 | ] | ||
99 | 99 | ||||
100 | return any(checker(function) for checker in checkers) | 100 | return any(checker(function) for checker in checkers) | ||
101 | 101 | ||||
102 | 102 | ||||
103 | def list_all_functions(module_name, member_keyword): | 103 | def list_all_functions(module_name, member_keyword): | ||
104 | stack = [module_name] | 104 | stack = [module_name] | ||
105 | functions = [] | 105 | functions = [] | ||
106 | 106 | ||||
107 | while stack: | 107 | while stack: | ||
108 | current = stack.pop() | 108 | current = stack.pop() | ||
109 | 109 | ||||
110 | members = getmembers(current) | 110 | members = getmembers(current) | ||
111 | functions.extend([value for _, value in members if isfunction(value)]) | 111 | functions.extend([value for _, value in members if isfunction(value)]) | ||
112 | 112 | ||||
113 | stack.extend( | 113 | stack.extend( | ||
114 | [value for name, value in members if member_keyword in name] | 114 | [value for name, value in members if member_keyword in name] | ||
115 | ) | 115 | ) | ||
116 | 116 | ||||
117 | return functions | 117 | return functions | ||
118 | 118 | ||||
119 | 119 | ||||
120 | def get_interesting_functions(): | 120 | def get_interesting_functions(): | ||
121 | member_keyword = "clue" | 121 | member_keyword = "clue" | ||
122 | 122 | ||||
123 | functions = list_all_functions(secret, member_keyword) | 123 | functions = list_all_functions(secret, member_keyword) | ||
124 | function_tester = ChallengeFunctionTester() | 124 | function_tester = ChallengeFunctionTester() | ||
125 | 125 | ||||
126 | return [ | 126 | return [ | ||
127 | function | 127 | function | ||
128 | for function in functions | 128 | for function in functions | ||
129 | if function_tester.is_interesting(function) | 129 | if function_tester.is_interesting(function) | ||
130 | ] | 130 | ] | ||
131 | 131 | ||||
132 | 132 | ||||
133 | def methodify(): | 133 | def methodify(): | ||
n | 134 | faculty_number = "IMMI" # 4MI0600097 | n | 134 | faculty_number = "4MI0600097" |
135 | interesting_functions = get_interesting_functions() | 135 | interesting_functions = get_interesting_functions() | ||
136 | 136 | ||||
137 | functions_by_name = { | 137 | functions_by_name = { | ||
138 | function.__name__: function for function in interesting_functions | 138 | function.__name__: function for function in interesting_functions | ||
139 | } | 139 | } | ||
140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | 140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | ||
141 | 141 | ||||
142 | return tuple(fn_functions) | 142 | return tuple(fn_functions) | ||
t | t | 143 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import string | f | 1 | import string |
2 | from inspect import getmembers, isfunction | 2 | from inspect import getmembers, isfunction | ||
3 | 3 | ||||
4 | import secret | 4 | import secret | ||
5 | 5 | ||||
6 | 6 | ||||
7 | class FunctionTester: | 7 | class FunctionTester: | ||
8 | def _is_specific_exception_function( | 8 | def _is_specific_exception_function( | ||
9 | self, function, exception_type, exception_message=None | 9 | self, function, exception_type, exception_message=None | ||
10 | ): | 10 | ): | ||
11 | try: | 11 | try: | ||
12 | function() | 12 | function() | ||
13 | except exception_type as exception: | 13 | except exception_type as exception: | ||
14 | is_correct_type = type(exception) is exception_type | 14 | is_correct_type = type(exception) is exception_type | ||
15 | if exception_message: | 15 | if exception_message: | ||
16 | return is_correct_type and str(exception) == exception_message | 16 | return is_correct_type and str(exception) == exception_message | ||
17 | 17 | ||||
18 | return is_correct_type | 18 | return is_correct_type | ||
19 | except BaseException: | 19 | except BaseException: | ||
20 | return False | 20 | return False | ||
21 | 21 | ||||
22 | return False | 22 | return False | ||
23 | 23 | ||||
24 | @staticmethod | 24 | @staticmethod | ||
25 | def _exception_guard(function): | 25 | def _exception_guard(function): | ||
26 | def wrapper(*args, **kwargs): | 26 | def wrapper(*args, **kwargs): | ||
27 | try: | 27 | try: | ||
28 | return function(*args, **kwargs) | 28 | return function(*args, **kwargs) | ||
29 | except BaseException: | 29 | except BaseException: | ||
30 | return False | 30 | return False | ||
31 | 31 | ||||
32 | return wrapper | 32 | return wrapper | ||
33 | 33 | ||||
34 | @_exception_guard | 34 | @_exception_guard | ||
35 | def _is_same_as_function(self, function, stub_function, test_cases): | 35 | def _is_same_as_function(self, function, stub_function, test_cases): | ||
36 | for args in test_cases: | 36 | for args in test_cases: | ||
37 | if function(*args) != stub_function(*args): | 37 | if function(*args) != stub_function(*args): | ||
38 | return False | 38 | return False | ||
39 | return True | 39 | return True | ||
40 | 40 | ||||
41 | 41 | ||||
42 | class ChallengeFunctionTester(FunctionTester): | 42 | class ChallengeFunctionTester(FunctionTester): | ||
43 | def is_type_error_function(self, function): | 43 | def is_type_error_function(self, function): | ||
44 | type_error_message = "Опаааааа, тука има нещо нередно." | 44 | type_error_message = "Опаааааа, тука има нещо нередно." | ||
45 | return self._is_specific_exception_function( | 45 | return self._is_specific_exception_function( | ||
46 | function, TypeError, type_error_message | 46 | function, TypeError, type_error_message | ||
47 | ) | 47 | ) | ||
48 | 48 | ||||
49 | def is_base_error_function(self, function): | 49 | def is_base_error_function(self, function): | ||
50 | return self._is_specific_exception_function(function, BaseException) | 50 | return self._is_specific_exception_function(function, BaseException) | ||
51 | 51 | ||||
52 | def is_int_function(self, function): | 52 | def is_int_function(self, function): | ||
53 | def int_function_stub(x): | 53 | def int_function_stub(x): | ||
54 | return x**2 if x % 2 == 0 else 0 | 54 | return x**2 if x % 2 == 0 else 0 | ||
55 | 55 | ||||
56 | int_test_range = 100 | 56 | int_test_range = 100 | ||
57 | 57 | ||||
58 | test_cases = [ | 58 | test_cases = [ | ||
59 | (el,) for el in range(-int_test_range, int_test_range + 1) | 59 | (el,) for el in range(-int_test_range, int_test_range + 1) | ||
60 | ] | 60 | ] | ||
61 | 61 | ||||
62 | return self._is_same_as_function( | 62 | return self._is_same_as_function( | ||
63 | function, int_function_stub, test_cases | 63 | function, int_function_stub, test_cases | ||
64 | ) | 64 | ) | ||
65 | 65 | ||||
66 | def is_string_function(self, function): | 66 | def is_string_function(self, function): | ||
67 | def _string_function_stub(left, right): | 67 | def _string_function_stub(left, right): | ||
68 | return left + right | 68 | return left + right | ||
69 | 69 | ||||
70 | string_test_cases = [ | 70 | string_test_cases = [ | ||
71 | ("a", "b"), | 71 | ("a", "b"), | ||
72 | ("abc", "123"), | 72 | ("abc", "123"), | ||
73 | ("XxX", ""), | 73 | ("XxX", ""), | ||
74 | ("", "YyY"), | 74 | ("", "YyY"), | ||
75 | ("", ""), | 75 | ("", ""), | ||
76 | ] | 76 | ] | ||
77 | return self._is_same_as_function( | 77 | return self._is_same_as_function( | ||
78 | function, _string_function_stub, string_test_cases | 78 | function, _string_function_stub, string_test_cases | ||
79 | ) | 79 | ) | ||
80 | 80 | ||||
81 | def is_static_function(self, function): | 81 | def is_static_function(self, function): | ||
82 | return False | 82 | return False | ||
83 | 83 | ||||
84 | def is_function_name_ok(self, function): | 84 | def is_function_name_ok(self, function): | ||
85 | allowed_characters = list(string.ascii_uppercase + string.digits) | 85 | allowed_characters = list(string.ascii_uppercase + string.digits) | ||
86 | return function.__name__ in allowed_characters | 86 | return function.__name__ in allowed_characters | ||
87 | 87 | ||||
88 | def is_interesting(self, function): | 88 | def is_interesting(self, function): | ||
89 | if not self.is_function_name_ok(function): | 89 | if not self.is_function_name_ok(function): | ||
90 | return False | 90 | return False | ||
91 | 91 | ||||
92 | checkers = [ | 92 | checkers = [ | ||
93 | self.is_type_error_function, | 93 | self.is_type_error_function, | ||
94 | self.is_base_error_function, | 94 | self.is_base_error_function, | ||
95 | self.is_int_function, | 95 | self.is_int_function, | ||
96 | self.is_string_function, | 96 | self.is_string_function, | ||
97 | self.is_static_function, | 97 | self.is_static_function, | ||
98 | ] | 98 | ] | ||
99 | 99 | ||||
100 | return any(checker(function) for checker in checkers) | 100 | return any(checker(function) for checker in checkers) | ||
101 | 101 | ||||
102 | 102 | ||||
103 | def list_all_functions(module_name, member_keyword): | 103 | def list_all_functions(module_name, member_keyword): | ||
104 | stack = [module_name] | 104 | stack = [module_name] | ||
105 | functions = [] | 105 | functions = [] | ||
106 | 106 | ||||
107 | while stack: | 107 | while stack: | ||
108 | current = stack.pop() | 108 | current = stack.pop() | ||
109 | 109 | ||||
110 | members = getmembers(current) | 110 | members = getmembers(current) | ||
111 | functions.extend([value for _, value in members if isfunction(value)]) | 111 | functions.extend([value for _, value in members if isfunction(value)]) | ||
112 | 112 | ||||
113 | stack.extend( | 113 | stack.extend( | ||
114 | [value for name, value in members if member_keyword in name] | 114 | [value for name, value in members if member_keyword in name] | ||
115 | ) | 115 | ) | ||
116 | 116 | ||||
117 | return functions | 117 | return functions | ||
118 | 118 | ||||
119 | 119 | ||||
120 | def get_interesting_functions(): | 120 | def get_interesting_functions(): | ||
121 | member_keyword = "clue" | 121 | member_keyword = "clue" | ||
122 | 122 | ||||
123 | functions = list_all_functions(secret, member_keyword) | 123 | functions = list_all_functions(secret, member_keyword) | ||
124 | function_tester = ChallengeFunctionTester() | 124 | function_tester = ChallengeFunctionTester() | ||
125 | 125 | ||||
126 | return [ | 126 | return [ | ||
127 | function | 127 | function | ||
128 | for function in functions | 128 | for function in functions | ||
129 | if function_tester.is_interesting(function) | 129 | if function_tester.is_interesting(function) | ||
130 | ] | 130 | ] | ||
131 | 131 | ||||
132 | 132 | ||||
133 | def methodify(): | 133 | def methodify(): | ||
134 | faculty_number = "IMMI" # 4MI0600097 | 134 | faculty_number = "IMMI" # 4MI0600097 | ||
135 | interesting_functions = get_interesting_functions() | 135 | interesting_functions = get_interesting_functions() | ||
136 | 136 | ||||
137 | functions_by_name = { | 137 | functions_by_name = { | ||
138 | function.__name__: function for function in interesting_functions | 138 | function.__name__: function for function in interesting_functions | ||
139 | } | 139 | } | ||
140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | 140 | fn_functions = [functions_by_name[letter] for letter in faculty_number] | ||
141 | 141 | ||||
142 | return tuple(fn_functions) | 142 | return tuple(fn_functions) | ||
t | 143 | t | |||
144 | |||||
145 | print(methodify()) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|