diff --git a/2023/day11/example1.txt b/2023/day11/example1.txt new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/2023/day11/example1.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... diff --git a/2023/day11/example2.txt b/2023/day11/example2.txt new file mode 100644 index 0000000..60d4399 --- /dev/null +++ b/2023/day11/example2.txt @@ -0,0 +1,2 @@ +#. +.# \ No newline at end of file diff --git a/2023/day11/src/part1.py b/2023/day11/src/part1.py new file mode 100644 index 0000000..4fd85a4 --- /dev/null +++ b/2023/day11/src/part1.py @@ -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) \ No newline at end of file diff --git a/2023/day11/src/part2.py b/2023/day11/src/part2.py new file mode 100644 index 0000000..3e550d6 --- /dev/null +++ b/2023/day11/src/part2.py @@ -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) \ No newline at end of file