add: days11
This commit is contained in:
parent
9459f5cc97
commit
5ab804addc
10
2023/day11/example1.txt
Normal file
10
2023/day11/example1.txt
Normal file
@ -0,0 +1,10 @@
|
||||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
..........
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
..........
|
||||
.......#..
|
||||
#...#.....
|
2
2023/day11/example2.txt
Normal file
2
2023/day11/example2.txt
Normal file
@ -0,0 +1,2 @@
|
||||
#.
|
||||
.#
|
34
2023/day11/src/part1.py
Normal file
34
2023/day11/src/part1.py
Normal file
@ -0,0 +1,34 @@
|
||||
text: str = open("input.txt", "r").read()
|
||||
|
||||
_value: int = 0
|
||||
|
||||
lines = text.splitlines()
|
||||
|
||||
empty_lines: int = 0
|
||||
cords: [(int, int)] = []
|
||||
for y, line in enumerate(lines):
|
||||
if "#" in line:
|
||||
for _ in range(line.count("#")):
|
||||
cords.append(y + empty_lines)
|
||||
else:
|
||||
empty_lines += 1
|
||||
|
||||
bozo: int = 0
|
||||
empty_colums: int = 0
|
||||
for x in range(len(lines[0])):
|
||||
apagnan = 1
|
||||
for y in range(len(lines)):
|
||||
if lines[y][x] == "#":
|
||||
apagnan = 0
|
||||
cords[bozo] = (x + empty_colums, cords[bozo])
|
||||
bozo += 1
|
||||
if apagnan:
|
||||
empty_colums += 1
|
||||
|
||||
while len(cords):
|
||||
xa, ya = cords.pop()
|
||||
print(xa, ya)
|
||||
for xb, yb in cords:
|
||||
_value += abs(xb - xa) + abs(yb - ya)
|
||||
|
||||
print(_value)
|
34
2023/day11/src/part2.py
Normal file
34
2023/day11/src/part2.py
Normal file
@ -0,0 +1,34 @@
|
||||
text: str = open("input.txt", "r").read()
|
||||
|
||||
_value: int = 0
|
||||
|
||||
lines = text.splitlines()
|
||||
|
||||
empty_lines: int = 0
|
||||
cords: [(int, int)] = []
|
||||
for y, line in enumerate(lines):
|
||||
if "#" in line:
|
||||
for _ in range(line.count("#")):
|
||||
cords.append(y + empty_lines)
|
||||
else:
|
||||
empty_lines += 1000000 -1
|
||||
|
||||
bozo: int = 0
|
||||
empty_colums: int = 0
|
||||
for x in range(len(lines[0])):
|
||||
apagnan = 1
|
||||
for y in range(len(lines)):
|
||||
if lines[y][x] == "#":
|
||||
apagnan = 0
|
||||
cords[bozo] = (x + empty_colums, cords[bozo])
|
||||
bozo += 1
|
||||
if apagnan:
|
||||
empty_colums += 1000000 -1
|
||||
|
||||
while len(cords):
|
||||
xa, ya = cords.pop()
|
||||
print(xa, ya)
|
||||
for xb, yb in cords:
|
||||
_value += abs(xb - xa) + abs(yb - ya)
|
||||
|
||||
print(_value)
|
Loading…
Reference in New Issue
Block a user