-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.py
More file actions
82 lines (56 loc) · 1.26 KB
/
Copy path6.py
File metadata and controls
82 lines (56 loc) · 1.26 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
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
75
76
77
78
79
import math
import collections
from collections import Counter
import re
from pyparsing import col
from tqdm import tqdm
TEST = """
123 328 51 64
45 64 387 23
6 98 215 314
* + * +
"""
PROD = "wow"
x = TEST
x = PROD
# x = x.strip()
# Data in differnt formats for quick access
text = x
lines = x.split("\n")
# grid = [list(line) for line in lines]
result = 0
# things = [l.split() for l in lines]
things = lines
# things = list(zip(*things))
last_line = things[-1]
cols = []
for i in range(len(last_line)):
if last_line[i] in ["+", "*"]:
cols.append(i)
print("Cols:", cols)
blobs = []
for i in range(len(cols)):
c1 = cols[i]
if i+1 >= len(cols):
c2 = len(lines[0])
else:
c2 = cols[i+1]
blob = []
for line in things:
blob.append(line[c1:c2])
blobs.append(blob)
print(blobs)
for *stuff, op in blobs:
stuff = ["".join(e) for e in list(zip(*[list(l) for l in stuff])) if "".join(e).strip() != ""]
print(stuff)
# exit()
c = int(stuff[0].replace(" ", ""))
for s in stuff[1:]:
if "*" in op:
c *= int(s.replace(" ", ""))
elif "+" in op:
c += int(s.replace(" ", "") )
print(c)
result += c
# input()
print("Result:", result)