-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_11.py
71 lines (59 loc) · 2.08 KB
/
Day_11.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
def part1():
emptyRows = [1 if i == "." * len(i) else 0 for i in inputVals]
emptyCols = []
for i in range(len(inputVals[0])):
empty = True
for j in range(len(inputVals)):
if inputVals[j][i] != ".": empty = False
if empty:
emptyCols.append(1)
else:
emptyCols.append(0)
emptyRowsPassed = 0
emptyColsPassed = 0
galaxys = []
for i in range(len(inputVals)):
if emptyRows[i] == 1: emptyRowsPassed += 1
emptyColsPassed = 0
for j in range(len(inputVals[i])):
if emptyCols[j] == 1: emptyColsPassed += 1
if inputVals[i][j] == "#":
galaxys.append((i + emptyRowsPassed, j + emptyColsPassed))
totalDist = 0
for i in range(len(galaxys)):
for j in range(i + 1, len(galaxys)):
totalDist += abs(galaxys[i][0] - galaxys[j][0]) + abs(galaxys[i][1] - galaxys[j][1])
print("Part 1:", totalDist)
def part2():
emptyRows = [1 if i == "." * len(i) else 0 for i in inputVals]
emptyCols = []
for i in range(len(inputVals[0])):
empty = True
for j in range(len(inputVals)):
if inputVals[j][i] != ".": empty = False
if empty:
emptyCols.append(1)
else:
emptyCols.append(0)
emptyRowsPassed = 0
emptyColsPassed = 0
galaxys = []
for i in range(len(inputVals)):
if emptyRows[i] == 1: emptyRowsPassed += 1000000 - 1
emptyColsPassed = 0
for j in range(len(inputVals[i])):
if emptyCols[j] == 1: emptyColsPassed += 1000000 - 1
if inputVals[i][j] == "#":
galaxys.append((i + emptyRowsPassed, j + emptyColsPassed))
totalDist = 0
for i in range(len(galaxys)):
for j in range(i + 1, len(galaxys)):
totalDist += abs(galaxys[i][0] - galaxys[j][0]) + abs(galaxys[i][1] - galaxys[j][1])
print("Part 2:", totalDist)
inputVals = []
f = open("Day_11_input.txt")
for line in f:
line = line.replace("\n", "")
inputVals.append(line)
part1()
part2()