-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc11_brackets.py
68 lines (58 loc) · 1.81 KB
/
cc11_brackets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import time
cc_number = 11
url_input = 'https://cc.the-morpheus.de/challenges/' + str(cc_number) + '/'
url_output = 'https://cc.the-morpheus.de/solutions/' + str(cc_number) + '/'
def solve():
response = requests.get(url_input).text
print('------------ Response of Server --------')
print(response)
print('----------------------------------------')
# TODO: programm your solution here
def is_bracket(term):
term = list(term)
brackets = []
for i in range(len(term)):
if term[i] == ')' and not brackets:
return False
if term[i] == '(':
brackets.append('(')
elif term[i] == ')':
brackets.append(')')
print(brackets)
if len(brackets) == 1:
return False
while brackets:
if brackets[0] == '(' and brackets[-1] == ')':
brackets.remove(brackets[-1])
brackets.remove(brackets[0])
else:
return False
return True
def is_bracket2(term):
opened = 0
for i in term:
if i == '(':
opened += 1
elif i == ')':
opened -= 1
if opened < 0:
return False
if opened != 0:
return False
return True
result = is_bracket2(response)
print(result)
result = is_bracket(response)
print(result)
response2 = requests.post(url_output, json={'token': result})
print('------------Response 2 of Server -------')
print(response2.text)
print('----------------------------------------')
# Success: TMT{t2VdCXazxCHu11K37BeS}
def benchmark(n):
start = time.time()
for i in range(n):
solve()
print((time.time() - start) / n)
benchmark(100)