diff --git a/2023/11/input1 b/2023/11/input1 new file mode 100644 index 0000000..a0bda53 --- /dev/null +++ b/2023/11/input1 @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... \ No newline at end of file diff --git a/2023/11/input2 b/2023/11/input2 new file mode 100644 index 0000000..53d22e0 --- /dev/null +++ b/2023/11/input2 @@ -0,0 +1,140 @@ +...........#..........#...........................#....................#......#........................................................#.... +...#........................#..............................#...................................................................#............ +......................................#...................................................................#...........#..................... +...............................................#...............#.......................#.................................................... +..........................................#...........#.............................................#....................................... +..........#.................................................................#................................#.............................. +................................#.................................................................................#......#.................. +..................................................................#......................................................................... +............................................................#..................#.......................................................#.... +................................................#............................................#...............................#.............. +.....#..............#..............................................................#................................#....................... +.........................................#...............................................#.................................................# +..............................#................................#.......#.................................................................... +........................................................................................................................#................... +...#......#.......#.................#...................#......................................#.......#.......#........................#... +...........................................#...............................#....................................................#........... +...................................................................................#........................................................ +.............#............#........................................#.......................................#......#......................... +................................#............................#...............................#.............................................. +........................................#.............#.........................#......#......................................#............. +........................................................................................................#.....#............................. +......#............#...............#..............#......................................................................................... +...........#..................#............#.....................#..................................................#....................... +.......................................................................#..................#................#.......................#........ +..#...................................#.....................................#.....#..................#...................................... +............................................................................................................................................ +............................#........................#.........................................#............................................ +.......#......................................................................................................................#............. +......................#.......................................................#............................................................. +.#...........................................................#.....#..................................................#.................#... +..................................#....................................................#.................................................... +.................................................................................#..............................#........................... +........#.................................#..........#......................................#............#.................................. +..................#........................................................#................................................................ +.............................#................#......................#...............................#..........................#......#.... +..............#......................#..................................................................................#................... +...............................................................................................................#............................ +..#.....................#.......................................#...................................................#....................... +..................................#....................#..........................................#......................................... +....................#.....................#......#.........................................................................#.......#........ +............................................................#..........#...................................................................# +....#........................#................................................#...........#...............#......#.......................... +............................................................................................................................................ +..........#............................#.................................................................................................... +...............#...............................#......#.............................................#.................................#..... +......................#..........#.........................#.......#..................................................#..................... +...............................................................................................................#..................#........# +............................................................................................................................................ +#..........................#...............................................#.......#......#................................................. +............................................................................................................................................ +.......#......................................................#............................................................#........#....... +.............................................#.........#............................................#.....#................................. +...............................#.......#.................................................................................................... +.................................................................#..........................#..................#............................ +..............#.....#.........................................................#......#.....................................................# +.................................................#.......#.............#.................................................................... +..............................................................#............................................#................................ +.#.......................#...............#.................................#.........................................................#...... +....................................#.....................................................#..............................#.................. +.....#...........#..............................................................................#.....#..................................... +.................................................................#.................#........................................................ +............................................................................................................................................ +.................................................#........................................................#................................. +........#.........................................................................................#...........................#..........#.. +...............#........#...........#.....#........................#..............................................#................#........ +........................................................................................#................................................... +...................................................................................#.........................#.............................. +...#..............#....................................................#............................#....................................... +..............................#............................#................................................................................ +........................................#.............................................................................................#..... +..............................................#..................#.............#........................#.................#................. +...................................................#.............................................................#.......................... +.........#.................................................................................................................................. +.......................#.....................................#.......#.....#..............................................................#. +................................................................................................#.....................#..................... +....#...........................#......................#.............................#.......................................#.............. +...........................................................................................................#................................ +...........#.......#........#..............................#.....................................................#.......................... +............................................#...............................................#............................................... +....................................................................#..............#..................#..............#...............#...... +.....................................#........................#............................................................................. +...............................................#............................................................#.................#............# +............................................................................................................................................ +....#.......#...........................................................................................................#.........#......... +...................................#................#...........#..............................#............................................ +............................................................................................................................................ +.......................................................................#...........#......#..........#.......#.............................. +..............................................................................#......................................................#...... +...........................#.....................#..................................................................#....................... +..#............#............................#................................................#.............................................. +...........................................................................................................................................# +........................................#...............#............#..........#......................................#.................... +............#................................................#.............................................................................. +.......#............................#...............#....................................#............#..........................#.......... +......................#....................................................#................................................................ +...............................................................................................#.............#.....#........................ +..................#....................................#.........#...............#.......................................................... +.............#...............#................#........................................#.................................................#.. +...................................#....................................................................#...................#............... +.........................................#..........#.................#..................................................................... +................#............................................................#.............................................................. +..........#.....................#........................#.....................................................................#............ +....#.................................#.............................................................................................#....... +......................#.....#.......................................................................................#....................... +..............................................#.........................................#................................................... +..........................................................................................................#................................. +...................................................................#.........................................................#.............. +.........#....................#.........#.........#...........#....................................#......................................#. +............................................................................................................................................ +..#........................................................................#...............#.............................#.................. +..............#...........#..........................................................#..........................................#........... +...................#.................................#...............................................#...................................... +...............................#......................................................................................................#..... +...........................................#.................#........#.......................#............................................. +.....................................#.....................................................................#......#.......#................. +................#...............................#................................#......#..........#......................................#. +........................#................................................................................................................... +..............................#................................................................................................#............ +.........................................................#...................#..........................#................................... +....#....................................................................................................................................... +........................................................................#........................#......................#.............#..... +............#...............#.............#.........#............................#........#................#................................ +.....................#...............#..............................................................................#....................... +..................................................................#......................................................................#.. +............................................................................................................................................ +..............#........................................#.....................#.......#...................................................... +........................#..............................................#..............................................#........#............ +........................................#........................................#.......................................................... +.......#........................#...................#.........#..............................................#.............................. +..#................#......................................................................#........................................#........ +.................................................................................................#.......................#.................. +..............................................#............................................................................................. +.....#........#...........................................................................................#.........#........#.............. +.................................................................................#..........#..........................................#.... +..........................#...................................#.........#..............#.........................................#.......... +............................................................................................................................................ +....................................................................#.......#...................#........................................... +......................#.............#.............#.....................................................#................................... +........................................................#........................................................#.......................... +..#..........#..........................#....................................................................................#.......#...... \ No newline at end of file diff --git a/2023/11/part1.py b/2023/11/part1.py new file mode 100644 index 0000000..768cee8 --- /dev/null +++ b/2023/11/part1.py @@ -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) \ No newline at end of file diff --git a/2023/11/part2.py b/2023/11/part2.py new file mode 100644 index 0000000..7d44468 --- /dev/null +++ b/2023/11/part2.py @@ -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) \ No newline at end of file