-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulbs.py
More file actions
47 lines (37 loc) · 1.3 KB
/
bulbs.py
File metadata and controls
47 lines (37 loc) · 1.3 KB
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
# 2011 southeast us 5776
string = "1 (3 (5)*3 2)*2 7"
timing_list = []
def find_matching_parens(string):
open_parens = 0
for i in range(len(string)):
if string[i] == '(':
open_parens += 1
if string[i] == ')':
open_parens -= 1
if open_parens == 0:
return i
def repeat_string(string, amount):
ret_string = ''
for i in range(amount):
ret_string += string[1:]
return string
def parse_timings(timings):
repeat_amount = 1
start_paren_index = 0
close_paren_index = len(timings)
if ('(') in timings:
start_paren_index = timings.find('(')
close_paren_index = find_matching_parens(timings[start_paren_index:]) + \
timings.find('(')
repeat_amount = int(timings[close_paren_index + 2:
timings.find(' ', close_paren_index + 2)])
return(timings[:start_paren_index] +
(parse_timings(timings[start_paren_index + 1:close_paren_index]) + ' ') * repeat_amount +
timings[timings.find(' ', close_paren_index):])
else:
return timings
timing_string = parse_timings(string).replace(' ', ' ')
timing_list = list(map(int, timing_string.split(' ')))
print(timing_list)
total_time = 1000
for i in range(total_time):