-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3a.py
52 lines (45 loc) · 1.21 KB
/
3a.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
data = open("3.in","r").read().split("\n")
nums = []
symbols = []
y = 0
for i in data:
x = 0
cn = ""
for c in i:
if c!=".":
if c in [str(x) for x in list(range(10))]:
cn += c
else:
symbols.append([x,y,c])
if cn!="":
allPoses = []
for j in range(x-len(cn),x):
allPoses.append([j,y])
nums.append([allPoses,int(cn),len(cn)])
cn = ""
else:
if cn!="":
allPoses = []
for j in range(x-len(cn),x):
allPoses.append([j,y])
nums.append([allPoses,int(cn),len(cn)])
cn = ""
x+=1
if cn!="":
allPoses = []
for j in range(x-len(cn),x):
allPoses.append([j,y])
nums.append([allPoses,int(cn),len(cn)])
cn = ""
y+=1
s = 0
print(len(nums))
for num in nums:
include = False
for symbol in symbols:
for pos in num[0]:
if pos[0]-1 <= symbol[0] <=pos[0]+1 and pos[1]-1 <= symbol[1] <=pos[1]+1:
include = True
if include:
s+=num[1]
print(s)