-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3_p2.py
74 lines (61 loc) · 2.2 KB
/
day3_p2.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
69
70
71
72
73
74
import re
# read input_data from file
with open("input_day3_p1.txt", "r") as file:
#with open("test.txt", "r") as file:
input_data = file.read()
thesum = 0
theosum = 0
#print(input_data[0])
#commands = re.findall("mul[(]\d+,\d+[)]",input_data[0])
#print(commands)
input_data = re.sub(r"don't\(\).*?(?:do\(\)|$)", "", input_data, flags=re.DOTALL)
commands = re.findall("mul\(\d+,\d+\)",input_data)
# for line in input_data:
# commands = []
# notCommands = []
# enable = True
# eol = False
# origLine=line
# while(not eol):
# if(enable):
# x = re.search("don't\(\)",line)
# if(x):
# parse = slice(0,x.start())
# news = re.findall("mul\(\d+,\d+\)",line[parse])
# commands.append(news)
# enable = False
# parse = slice(x.end(),len(line))
# line = line[parse]
# else:
# eol = True
# news = re.findall("mul\(\d+,\d+\)",line)
# commands.append(news)
# else:
# x = re.search("do\(\)",line)
# if(x):
# #debug
# parse = slice(0,x.start())
# news = re.findall("mul\(\d+,\d+\)",line[parse])
# notCommands.append(news)
# #debug
# enable = True
# parse = slice(x.end(),len(line))
# line = line[parse]
# else:
# eol = True
# #sett = re.findall("mul[(]\d+,\d+[)]",line)
# origCommands = re.findall("mul[(]\d+,\d+[)]",origLine)
# for sett in commands:
# for mul in sett:
# factors = re.findall("\d+",mul)
# thesum += int(factors[0]) * int(factors[1])
# for nsett in notCommands:
# for nmul in nsett:
# factors = re.findall("\d+",nmul)
# thesum += int(factors[0]) * int(factors[1])
for mul in commands:
factors = re.findall("\d+",mul)
thesum += int(factors[0]) * int(factors[1])
print("Sum is ",thesum)
#141,441,084 current no filter but going through logic
#170,807,108 correct all