mirror of
https://github.com/danbulant/adventOfCode
synced 2026-05-20 04:38:34 +00:00
day 11
This commit is contained in:
parent
13429a150d
commit
c664e38c94
4 changed files with 242 additions and 0 deletions
10
2023/11/input1
Normal file
10
2023/11/input1
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
..........
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
..........
|
||||
.......#..
|
||||
#...#.....
|
||||
140
2023/11/input2
Normal file
140
2023/11/input2
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
...........#..........#...........................#....................#......#........................................................#....
|
||||
...#........................#..............................#...................................................................#............
|
||||
......................................#...................................................................#...........#.....................
|
||||
...............................................#...............#.......................#....................................................
|
||||
..........................................#...........#.............................................#.......................................
|
||||
..........#.................................................................#................................#..............................
|
||||
................................#.................................................................................#......#..................
|
||||
..................................................................#.........................................................................
|
||||
............................................................#..................#.......................................................#....
|
||||
................................................#............................................#...............................#..............
|
||||
.....#..............#..............................................................#................................#.......................
|
||||
.........................................#...............................................#.................................................#
|
||||
..............................#................................#.......#....................................................................
|
||||
........................................................................................................................#...................
|
||||
...#......#.......#.................#...................#......................................#.......#.......#........................#...
|
||||
...........................................#...............................#....................................................#...........
|
||||
...................................................................................#........................................................
|
||||
.............#............#........................................#.......................................#......#.........................
|
||||
................................#............................#...............................#..............................................
|
||||
........................................#.............#.........................#......#......................................#.............
|
||||
........................................................................................................#.....#.............................
|
||||
......#............#...............#..............#.........................................................................................
|
||||
...........#..................#............#.....................#..................................................#.......................
|
||||
.......................................................................#..................#................#.......................#........
|
||||
..#...................................#.....................................#.....#..................#......................................
|
||||
............................................................................................................................................
|
||||
............................#........................#.........................................#............................................
|
||||
.......#......................................................................................................................#.............
|
||||
......................#.......................................................#.............................................................
|
||||
.#...........................................................#.....#..................................................#.................#...
|
||||
..................................#....................................................#....................................................
|
||||
.................................................................................#..............................#...........................
|
||||
........#.................................#..........#......................................#............#..................................
|
||||
..................#........................................................#................................................................
|
||||
.............................#................#......................#...............................#..........................#......#....
|
||||
..............#......................#..................................................................................#...................
|
||||
...............................................................................................................#............................
|
||||
..#.....................#.......................................#...................................................#.......................
|
||||
..................................#....................#..........................................#.........................................
|
||||
....................#.....................#......#.........................................................................#.......#........
|
||||
............................................................#..........#...................................................................#
|
||||
....#........................#................................................#...........#...............#......#..........................
|
||||
............................................................................................................................................
|
||||
..........#............................#....................................................................................................
|
||||
...............#...............................#......#.............................................#.................................#.....
|
||||
......................#..........#.........................#.......#..................................................#.....................
|
||||
...............................................................................................................#..................#........#
|
||||
............................................................................................................................................
|
||||
#..........................#...............................................#.......#......#.................................................
|
||||
............................................................................................................................................
|
||||
.......#......................................................#............................................................#........#.......
|
||||
.............................................#.........#............................................#.....#.................................
|
||||
...............................#.......#....................................................................................................
|
||||
.................................................................#..........................#..................#............................
|
||||
..............#.....#.........................................................#......#.....................................................#
|
||||
.................................................#.......#.............#....................................................................
|
||||
..............................................................#............................................#................................
|
||||
.#.......................#...............#.................................#.........................................................#......
|
||||
....................................#.....................................................#..............................#..................
|
||||
.....#...........#..............................................................................#.....#.....................................
|
||||
.................................................................#.................#........................................................
|
||||
............................................................................................................................................
|
||||
.................................................#........................................................#.................................
|
||||
........#.........................................................................................#...........................#..........#..
|
||||
...............#........#...........#.....#........................#..............................................#................#........
|
||||
........................................................................................#...................................................
|
||||
...................................................................................#.........................#..............................
|
||||
...#..............#....................................................#............................#.......................................
|
||||
..............................#............................#................................................................................
|
||||
........................................#.............................................................................................#.....
|
||||
..............................................#..................#.............#........................#.................#.................
|
||||
...................................................#.............................................................#..........................
|
||||
.........#..................................................................................................................................
|
||||
.......................#.....................................#.......#.....#..............................................................#.
|
||||
................................................................................................#.....................#.....................
|
||||
....#...........................#......................#.............................#.......................................#..............
|
||||
...........................................................................................................#................................
|
||||
...........#.......#........#..............................#.....................................................#..........................
|
||||
............................................#...............................................#...............................................
|
||||
....................................................................#..............#..................#..............#...............#......
|
||||
.....................................#........................#.............................................................................
|
||||
...............................................#............................................................#.................#............#
|
||||
............................................................................................................................................
|
||||
....#.......#...........................................................................................................#.........#.........
|
||||
...................................#................#...........#..............................#............................................
|
||||
............................................................................................................................................
|
||||
.......................................................................#...........#......#..........#.......#..............................
|
||||
..............................................................................#......................................................#......
|
||||
...........................#.....................#..................................................................#.......................
|
||||
..#............#............................#................................................#..............................................
|
||||
...........................................................................................................................................#
|
||||
........................................#...............#............#..........#......................................#....................
|
||||
............#................................................#..............................................................................
|
||||
.......#............................#...............#....................................#............#..........................#..........
|
||||
......................#....................................................#................................................................
|
||||
...............................................................................................#.............#.....#........................
|
||||
..................#....................................#.........#...............#..........................................................
|
||||
.............#...............#................#........................................#.................................................#..
|
||||
...................................#....................................................................#...................#...............
|
||||
.........................................#..........#.................#.....................................................................
|
||||
................#............................................................#..............................................................
|
||||
..........#.....................#........................#.....................................................................#............
|
||||
....#.................................#.............................................................................................#.......
|
||||
......................#.....#.......................................................................................#.......................
|
||||
..............................................#.........................................#...................................................
|
||||
..........................................................................................................#.................................
|
||||
...................................................................#.........................................................#..............
|
||||
.........#....................#.........#.........#...........#....................................#......................................#.
|
||||
............................................................................................................................................
|
||||
..#........................................................................#...............#.............................#..................
|
||||
..............#...........#..........................................................#..........................................#...........
|
||||
...................#.................................#...............................................#......................................
|
||||
...............................#......................................................................................................#.....
|
||||
...........................................#.................#........#.......................#.............................................
|
||||
.....................................#.....................................................................#......#.......#.................
|
||||
................#...............................#................................#......#..........#......................................#.
|
||||
........................#...................................................................................................................
|
||||
..............................#................................................................................................#............
|
||||
.........................................................#...................#..........................#...................................
|
||||
....#.......................................................................................................................................
|
||||
........................................................................#........................#......................#.............#.....
|
||||
............#...............#.............#.........#............................#........#................#................................
|
||||
.....................#...............#..............................................................................#.......................
|
||||
..................................................................#......................................................................#..
|
||||
............................................................................................................................................
|
||||
..............#........................................#.....................#.......#......................................................
|
||||
........................#..............................................#..............................................#........#............
|
||||
........................................#........................................#..........................................................
|
||||
.......#........................#...................#.........#..............................................#..............................
|
||||
..#................#......................................................................#........................................#........
|
||||
.................................................................................................#.......................#..................
|
||||
..............................................#.............................................................................................
|
||||
.....#........#...........................................................................................#.........#........#..............
|
||||
.................................................................................#..........#..........................................#....
|
||||
..........................#...................................#.........#..............#.........................................#..........
|
||||
............................................................................................................................................
|
||||
....................................................................#.......#...................#...........................................
|
||||
......................#.............#.............#.....................................................#...................................
|
||||
........................................................#........................................................#..........................
|
||||
..#..........#..........................#....................................................................................#.......#......
|
||||
48
2023/11/part1.py
Normal file
48
2023/11/part1.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
map = []
|
||||
|
||||
for line in open("./input1"):
|
||||
map.append([x for x in line.strip()])
|
||||
|
||||
emptyRows = []
|
||||
emptyCols = []
|
||||
|
||||
for i in range(len(map)):
|
||||
if map[i].count(".") == len(map[i]):
|
||||
emptyRows.append(i)
|
||||
|
||||
for i in range(len(map[0])):
|
||||
if [x[i] for x in map].count(".") == len(map):
|
||||
emptyCols.append(i)
|
||||
|
||||
emptyRows.reverse()
|
||||
emptyCols.reverse()
|
||||
|
||||
for i in emptyRows:
|
||||
# Add another empty row at the selected index
|
||||
map.insert(i, ["." for x in range(len(map[0]))])
|
||||
|
||||
for i in emptyCols:
|
||||
# Add another empty column at the selected index
|
||||
for j in range(len(map)):
|
||||
map[j].insert(i, ".")
|
||||
|
||||
# for line in map:
|
||||
# print("".join(line))
|
||||
|
||||
galaxies = []
|
||||
|
||||
for i in range(len(map)):
|
||||
for j in range(len(map[i])):
|
||||
if map[i][j] == "#":
|
||||
galaxies.append((i, j))
|
||||
|
||||
counter = 0
|
||||
for x in range(len(galaxies)):
|
||||
for y in range(x, len(galaxies)):
|
||||
if x == y: continue
|
||||
galaxy = galaxies[x]
|
||||
galaxy2 = galaxies[y]
|
||||
counter += abs(galaxy[0] - galaxy2[0]) + abs(galaxy[1] - galaxy2[1])
|
||||
|
||||
print(counter)
|
||||
44
2023/11/part2.py
Normal file
44
2023/11/part2.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
map = []
|
||||
|
||||
for line in open("./input2"):
|
||||
map.append([x for x in line.strip()])
|
||||
|
||||
multiplier = 1_000_000 -1
|
||||
|
||||
emptyRows = []
|
||||
emptyCols = []
|
||||
|
||||
for i in range(len(map)):
|
||||
if map[i].count(".") == len(map[i]):
|
||||
emptyRows.append(i)
|
||||
|
||||
for i in range(len(map[0])):
|
||||
if [x[i] for x in map].count(".") == len(map):
|
||||
emptyCols.append(i)
|
||||
|
||||
emptyRows.reverse()
|
||||
emptyCols.reverse()
|
||||
|
||||
# for line in map:
|
||||
# print("".join(line))
|
||||
|
||||
print(emptyRows)
|
||||
print(emptyCols)
|
||||
|
||||
galaxies = []
|
||||
|
||||
for i in range(len(map)):
|
||||
for j in range(len(map[i])):
|
||||
if map[i][j] == "#":
|
||||
galaxies.append((i + (len([x for x in emptyRows if x < i])) * multiplier, j + (len([x for x in emptyCols if x < j])) * multiplier))
|
||||
|
||||
counter = 0
|
||||
for x in range(len(galaxies)):
|
||||
for y in range(x, len(galaxies)):
|
||||
if x == y: continue
|
||||
galaxy = galaxies[x]
|
||||
galaxy2 = galaxies[y]
|
||||
counter += abs(galaxy[0] - galaxy2[0]) + abs(galaxy[1] - galaxy2[1])
|
||||
|
||||
print(counter)
|
||||
Loading…
Reference in a new issue