add: days11

This commit is contained in:
starnakin 2023-12-11 08:49:13 +01:00
parent 9459f5cc97
commit 5ab804addc
4 changed files with 80 additions and 0 deletions

10
2023/day11/example1.txt Normal file
View File

@ -0,0 +1,10 @@
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....

2
2023/day11/example2.txt Normal file
View File

@ -0,0 +1,2 @@
#.
.#

34
2023/day11/src/part1.py Normal file
View 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
View 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)