Passed
Push — main ( 2b7d7b...7005b6 )
by Yohann
01:05
created

foo   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 15
dl 0
loc 22
rs 10
c 0
b 0
f 0
1
# To match the format of input files for the Basilisk.
2
q = { 11: open("inputs/day_11_input.txt").read() }
3
4
######################### PART 1: MULTI-LINE SOLUTION #########################
5
galaxies = [(x, y) for y, row in enumerate(q[11].strip().split()) for x, col in enumerate(row) if col == '#']
6
7
max_x = max(galaxies, key=lambda x: x[0])[0]
8
max_y = max(galaxies, key=lambda x: x[1])[1]
9
10
empty_rows = [y for y in range(max_y+1) if not any([y == g[1] for g in galaxies])]
11
empty_cols = [x for x in range(max_x+1) if not any([x == g[0] for g in galaxies])]
12
13
galaxies = [(g[0] + len([x for x in empty_cols if x < g[0]]), g[1] + len([y for y in empty_rows if y < g[1]])) for g in galaxies]
14
15
shortest_paths = {}
16
for g1 in galaxies:
17
    for g2 in galaxies:
18
        if g1 != g2 and (g2, g1) not in shortest_paths:
19
            shortest_paths[(g1, g2)] = abs(g1[0] - g2[0]) + abs(g1[1] - g2[1])
20
            
21
print('Day 11 Part 1:',sum(shortest_paths.values()))
22