-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11b.py
47 lines (35 loc) · 985 Bytes
/
11b.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
data = open("11.in","r").read().split("\n")
allemptyColumns = []
allEmptyRows = []
for x in range(len(data[0])):
allZeros = True
for y in range(len(data)):
if data[y][x]!=".":
allZeros = False
if allZeros:
allemptyColumns.append(x)
for y in range(len(data)):
allZeros = True
for x in range(len(data[0])):
if data[y][x]!=".":
allZeros = False
if allZeros:
allEmptyRows.append(y)
allGalaxies = []
nya = 0
for y in range(len(data)):
if y in allEmptyRows:
nya+=999999
nxa = 0
for x in range(len(data[0])):
if x in allemptyColumns:
nxa += 999999
if data[y][x] == "#":
ey = y + nya
ex = x + nxa
allGalaxies.append([ey,ex])
out = 0
for i in range(len(allGalaxies)):
for j in range(len(allGalaxies)):
out += abs(allGalaxies[i][0]-allGalaxies[j][0]) + abs(allGalaxies[i][1]-allGalaxies[j][1])
print(out//2)