Предизвикателства > Сляпа баба > Решения > Решението на Мирослав Стояновски

Резултати
0 точки от тестове
1 точки от учител

1 точки общо

0 успешни теста
0 неуспешни теста
Код

 1import secret
 2import inspect
 3
 4def is_interesting(obj, outer):
 5    if not hasattr(obj, '__call__'):
 6        return False
 7    if not len(obj.__name__) == 1:
 8        return False
 9    if not (obj.__name__.isupper() or obj.__name__.isdigit()):
10        return False
11    
12    #check if it is staticmethod
13    if not hasattr(outer, '__name__') or not outer.__name__ is 'secret':
14        if isinstance(inspect.getattr_static(outer.__class__, obj.__name__), staticmethod):
15            return True
16    
17
18    #get the obj function bound to outer
19    func = getattr(outer, obj.__name__)
20       
21    #check if it throws exception with 0 args
22    try:
23        func()
24    except TypeError as e:
25        if type(e) is TypeError and str(e) == 'Опаааааа, тука има нещо нередно.':
26            return True
27    except BaseException as e:
28        if type(e) is BaseException:
29            return True
30    
31    #check if f(x) = x^2 (x is even) or f(x) = 0 (x is odd)
32    try:
33        magic = 69420
34        magic2 = 13121337
35        if magic ** 2 == func(magic) and 0 == func(magic2):
36            return True
37    except TypeError:
38        pass
39    except Exception:
40        return False
41    
42    #check if it concatinates
43    try:
44        magic = 'baba'
45        magic2 = 'dyado'
46        if (magic + magic2) is func(left = magic, right = magic2):
47            return True
48    except Exception:
49        return False
50    
51    return False
52
53
54def get_objects_from(current_object, previous_object = None):
55    '''Get all leaf nodes from current_object member hierarchy. 
56       It is clear that functions can only be leaf nodes. '''
57    
58    interesting_methods = []
59    is_leaf = True
60    for current_attribute in dir(current_object):
61        #if it is not leaf and contains 'clue', go deeper into recursion
62        if 'clue' in current_attribute:
63            is_leaf = False
64            interesting_methods.extend(get_objects_from(getattr(current_object, current_attribute), current_object))
65        if is_interesting(getattr(current_object, current_attribute), current_object):
66            is_leaf = False
67            interesting_methods.append(getattr(current_object, current_attribute))
68
69    if not is_leaf:
70        return interesting_methods
71    
72    #recursion base
73    return [current_object] if is_interesting(current_object, previous_object) else []    
74
75
76def methodify():
77    faculty_number = '5MI0600195'
78    interesting_methods = get_objects_from(secret)
79    my_methods = []
80    current_index = 0
81
82    while current_index < len(faculty_number):
83        for method in interesting_methods:
84            if method.__name__ is faculty_number[current_index]:
85                my_methods.append(method)
86                current_index = current_index + 1
87                break
88
89    return tuple(my_methods)

Timed out.

Дискусия
История
Това решение има само една версия.