-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.py
59 lines (50 loc) · 1.25 KB
/
3.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
from lib import (
read_file,
lookAround,
isDiagonalAdj
)
test_run = 1
if test_run == 0:
a = read_file("exem")
else:
a = read_file("input")
symbols = {"*", "#", "$", "&", "%", "^", "!", "@", "+", "=", "/", "-"}
arr = []
for line in a:
arr.append([*line])
nu = {"1","2","3","4","5","6","7","8","9","0"}
def isNum(item):
return item in nu
def getNum(i,j,arr):
if arr[i][j] not in nu:
return 0 , arr
n = arr[i][j]
j1 = j + 1
while j1 < len(arr) and arr[i][j1] in nu:
n += arr[i][j1]
arr[i][j1] = "."
j1 += 1
j1 = j-1
while j1 >= 0 and arr[i][j1] in nu:
n = arr[i][j1] + n
arr[i][j1] = "."
j1 -= 1
return int(n), arr
su = 0
for i in range(len(arr)):
for j in range(len(arr[i])):
if arr[i][j] in symbols:
if arr[i][j] != "*":
continue
print(lookAround(i,j,arr, isNum))
mul = 1
seen = 0
for k,l in lookAround(i,j,arr, isNum):
n, arr = getNum(k,l,arr)
if n > 0:
seen += 1
mul *= n
if seen == 2:
su += mul
break
print(su)