-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc12_minlenarray.py
47 lines (38 loc) · 1.29 KB
/
cc12_minlenarray.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
import requests
import time
cc_number = 12
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).json()
print('------------ Response of Server --------')
print(response)
print('----------------------------------------')
# TODO: programm your solution here
k = response['k']
liste = response['list']
def min_length(k, liste):
minimal = len(liste)
for i in range(len(liste)):
index_length, value = 0, 0
for j in range(i, len(liste)):
if value >= k:
if index_length < minimal:
minimal = index_length
break
index_length += 1
value += liste[j]
return minimal
result = min_length(k, liste)
print(result)
response2 = requests.post(url_output, json={'token': result})
print('------------Response 2 of Server -------')
print(response2.text)
print('----------------------------------------')
# Success: TMT{IeNdTke0JJONqwbel1HJ}
def benchmark(n):
start = time.time()
for i in range(n):
solve()
print((time.time() - start) / n)
benchmark(10)