Skip to content

Commit 7007ebf

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 8ff2c3b + f5ba757 commit 7007ebf

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed

2023/day11/main1.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
def expand_space(lines: list[str], ):
2+
...
3+
4+
5+
def solution(lines: list[str]):
6+
lines = [line for line in lines if line != '']
7+
ret = 0
8+
bigger_rows = []
9+
no_galaxy_in_cols = [True] * len(lines)
10+
galaxy_coords = []
11+
for i in range(len(lines)):
12+
no_galaxy_in_row = True
13+
for j in range(len(lines[i])):
14+
if lines[i][j] == '#':
15+
no_galaxy_in_row = False
16+
no_galaxy_in_cols[j] = False
17+
galaxy_coords.append((i, j))
18+
if no_galaxy_in_row:
19+
bigger_rows.append(i)
20+
bigger_cols = [i for i in range(len(no_galaxy_in_cols)) if no_galaxy_in_cols[i]]
21+
for i, (g1_i, g1_j) in enumerate(galaxy_coords):
22+
for j, (g2_i, g2_j) in enumerate(galaxy_coords[i:]):
23+
r = 0
24+
if g1_i == g2_i and g1_j == g2_j:
25+
continue
26+
i_range = range(min(g1_i, g2_i) + 1, max(g1_i, g2_i))
27+
j_range = range(min(g1_j, g2_j) + 1, max(g1_j, g2_j))
28+
if g1_i != g2_i:
29+
r += 1
30+
if g1_j != g2_j:
31+
r += 1
32+
for step_i in i_range:
33+
r += 2 if step_i in bigger_rows else 1
34+
for step_j in j_range:
35+
r += 2 if step_j in bigger_cols else 1
36+
ret += r
37+
return ret
38+
39+
40+
data = '''...#......
41+
.......#..
42+
#.........
43+
..........
44+
......#...
45+
.#........
46+
.........#
47+
..........
48+
.......#..
49+
#...#.....
50+
'''.split('\n')
51+
52+
# data = ''' v v v
53+
# ...#......
54+
# .......#..
55+
# #.........
56+
# >..........<
57+
# ......#...
58+
# .#........
59+
# .........#
60+
# >..........<
61+
# .......#..
62+
# #...#.....
63+
# ^ ^ ^
64+
# '''.split('\n')
65+
66+
# data = '''....#........
67+
# .........#...
68+
# #............
69+
# .............
70+
# .............
71+
# ........#....
72+
# .#...........
73+
# ............#
74+
# .............
75+
# .............
76+
# .........#...
77+
# #....#.......
78+
# '''.split('\n')
79+
80+
# data = '''....1........
81+
# .........2...
82+
# 3............
83+
# .............
84+
# .............
85+
# ........4....
86+
# .5...........
87+
# ............6
88+
# .............
89+
# .............
90+
# .........7...
91+
# 8....9.......
92+
# '''.split('\n')
93+
94+
# data = '''....1........
95+
# .........2...
96+
# 3............
97+
# .............
98+
# .............
99+
# ........4....
100+
# .5...........
101+
# .##.........6
102+
# ..##.........
103+
# ...##........
104+
# ....##...7...
105+
# 8....9.......
106+
# '''.split('\n')
107+
108+
data = open('input.txt', 'r').read().split('\n')
109+
110+
print(solution(data))

2023/day11/main2.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
def expand_space(lines: list[str], ):
2+
...
3+
4+
5+
def solution(lines: list[str]):
6+
lines = [line for line in lines if line != '']
7+
ret = 0
8+
bigger_rows = []
9+
no_galaxy_in_cols = [True] * len(lines)
10+
galaxy_coords = []
11+
for i in range(len(lines)):
12+
no_galaxy_in_row = True
13+
for j in range(len(lines[i])):
14+
if lines[i][j] == '#':
15+
no_galaxy_in_row = False
16+
no_galaxy_in_cols[j] = False
17+
galaxy_coords.append((i, j))
18+
if no_galaxy_in_row:
19+
bigger_rows.append(i)
20+
bigger_cols = [i for i in range(len(no_galaxy_in_cols)) if no_galaxy_in_cols[i]]
21+
for i, (g1_i, g1_j) in enumerate(galaxy_coords):
22+
for j, (g2_i, g2_j) in enumerate(galaxy_coords[i:]):
23+
r = 0
24+
if g1_i == g2_i and g1_j == g2_j:
25+
continue
26+
i_range = range(min(g1_i, g2_i) + 1, max(g1_i, g2_i))
27+
j_range = range(min(g1_j, g2_j) + 1, max(g1_j, g2_j))
28+
if g1_i != g2_i:
29+
r += 1
30+
if g1_j != g2_j:
31+
r += 1
32+
for step_i in i_range:
33+
r += 1000000 if step_i in bigger_rows else 1
34+
for step_j in j_range:
35+
r += 1000000 if step_j in bigger_cols else 1
36+
ret += r
37+
return ret
38+
39+
40+
data = '''...#......
41+
.......#..
42+
#.........
43+
..........
44+
......#...
45+
.#........
46+
.........#
47+
..........
48+
.......#..
49+
#...#.....
50+
'''.split('\n')
51+
52+
# data = ''' v v v
53+
# ...#......
54+
# .......#..
55+
# #.........
56+
# >..........<
57+
# ......#...
58+
# .#........
59+
# .........#
60+
# >..........<
61+
# .......#..
62+
# #...#.....
63+
# ^ ^ ^
64+
# '''.split('\n')
65+
66+
# data = '''....#........
67+
# .........#...
68+
# #............
69+
# .............
70+
# .............
71+
# ........#....
72+
# .#...........
73+
# ............#
74+
# .............
75+
# .............
76+
# .........#...
77+
# #....#.......
78+
# '''.split('\n')
79+
80+
# data = '''....1........
81+
# .........2...
82+
# 3............
83+
# .............
84+
# .............
85+
# ........4....
86+
# .5...........
87+
# ............6
88+
# .............
89+
# .............
90+
# .........7...
91+
# 8....9.......
92+
# '''.split('\n')
93+
94+
# data = '''....1........
95+
# .........2...
96+
# 3............
97+
# .............
98+
# .............
99+
# ........4....
100+
# .5...........
101+
# .##.........6
102+
# ..##.........
103+
# ...##........
104+
# ....##...7...
105+
# 8....9.......
106+
# '''.split('\n')
107+
108+
data = open('input.txt', 'r').read().split('\n')
109+
110+
print(solution(data))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy