2023 - Day 11 part 1
This commit is contained in:
		
							parent
							
								
									723d2fc3d1
								
							
						
					
					
						commit
						db50f6b206
					
				
					 3 changed files with 222 additions and 0 deletions
				
			
		
							
								
								
									
										72
									
								
								2023/11/11.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								2023/11/11.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,72 @@
 | 
				
			||||||
 | 
					#!/usr/bin/env python
 | 
				
			||||||
 | 
					# 2023 - Advent Of Code 11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# file = 'input_example.txt'
 | 
				
			||||||
 | 
					file = 'input.txt'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# pylint: disable=consider-using-with
 | 
				
			||||||
 | 
					input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
 | 
				
			||||||
 | 
					print(f'map: ({len(input_lines[0])}, {len(input_lines)})')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# find empty lines
 | 
				
			||||||
 | 
					empty_lines = []
 | 
				
			||||||
 | 
					for y, _ in enumerate(input_lines):
 | 
				
			||||||
 | 
					    if '#' not in input_lines[y]:
 | 
				
			||||||
 | 
					        empty_lines.append(y)
 | 
				
			||||||
 | 
					print(f'empty lines: {empty_lines}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# find empty columns
 | 
				
			||||||
 | 
					empty_columns = []
 | 
				
			||||||
 | 
					for x in range(0, len(input_lines[0])):
 | 
				
			||||||
 | 
					    empty = True
 | 
				
			||||||
 | 
					    for y, _ in enumerate(input_lines):
 | 
				
			||||||
 | 
					        if input_lines[y][x] == '#':
 | 
				
			||||||
 | 
					            empty = False
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					    if empty:
 | 
				
			||||||
 | 
					        empty_columns.append(x)
 | 
				
			||||||
 | 
					print(f'empty columns: {empty_columns}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# expand lines
 | 
				
			||||||
 | 
					eline = "".join(['.'] * len(input_lines[0]))
 | 
				
			||||||
 | 
					offset = 0
 | 
				
			||||||
 | 
					for l in empty_lines:
 | 
				
			||||||
 | 
					    input_lines.insert(l+offset, eline)
 | 
				
			||||||
 | 
					    offset += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# expand columns
 | 
				
			||||||
 | 
					offset = 0
 | 
				
			||||||
 | 
					for c in empty_columns:
 | 
				
			||||||
 | 
					    for y, line in enumerate(input_lines):
 | 
				
			||||||
 | 
					        s = line[:c+offset] + '.' + line[c+offset:]
 | 
				
			||||||
 | 
					        input_lines[y] = s
 | 
				
			||||||
 | 
					    offset += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stars = []
 | 
				
			||||||
 | 
					for y, _ in enumerate(input_lines):
 | 
				
			||||||
 | 
					    for x, _ in enumerate(_):
 | 
				
			||||||
 | 
					        if input_lines[y][x] == '#':
 | 
				
			||||||
 | 
					            stars.append((x, y))
 | 
				
			||||||
 | 
					print(f'stars: {len(stars)}, extended map: ({len(input_lines[0])}, {len(input_lines)})')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# for y in range(0, len(input_lines)):
 | 
				
			||||||
 | 
					#     for x in range(0, len(input_lines[y])):
 | 
				
			||||||
 | 
					#         print(input_lines[y][x], end='')
 | 
				
			||||||
 | 
					#     print()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					paths = []
 | 
				
			||||||
 | 
					for s1 in stars:
 | 
				
			||||||
 | 
					    for s2 in stars:
 | 
				
			||||||
 | 
					        if s1 != s2 and {s1, s2} not in paths:
 | 
				
			||||||
 | 
					            paths.append({s1, s2})
 | 
				
			||||||
 | 
					print(f'number of paths: {len(paths)}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# dist = math.abs(x2-x1) + math.abs(y2-y1)
 | 
				
			||||||
 | 
					path_sum = 0
 | 
				
			||||||
 | 
					for path in paths:
 | 
				
			||||||
 | 
					    p = list(path)
 | 
				
			||||||
 | 
					    dist = abs(p[0][0] - p[1][0]) + abs(p[0][1] - p[1][1])
 | 
				
			||||||
 | 
					    path_sum += dist
 | 
				
			||||||
 | 
					    # print(f'{path} dist: {dist}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print(f'{path_sum=}')
 | 
				
			||||||
							
								
								
									
										140
									
								
								2023/11/input.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								2023/11/input.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,140 @@
 | 
				
			||||||
 | 
					.........................#.........#..................#..............#.......#.....#........................#............#.....#...........#
 | 
				
			||||||
 | 
					.............................................#.....................................................#........................................
 | 
				
			||||||
 | 
					.......#............#..........#............................................................................................................
 | 
				
			||||||
 | 
					.#................................................#........#.............................................#..............................#...
 | 
				
			||||||
 | 
					................#.....................#.............................................................................#.......................
 | 
				
			||||||
 | 
					........................................................................#....................#................#...........#.................
 | 
				
			||||||
 | 
					...........................................#........................................#.......................................................
 | 
				
			||||||
 | 
					..................................#......................#.......#...........#..............................................................
 | 
				
			||||||
 | 
					..........#.................................................................................................................................
 | 
				
			||||||
 | 
					..............................................#..........................................#.....................................#............
 | 
				
			||||||
 | 
					..........................................................................#.................................................................
 | 
				
			||||||
 | 
					...#................#...........#.......#............................#...............................#......................................
 | 
				
			||||||
 | 
					.........................................................................................................................#..................
 | 
				
			||||||
 | 
					.............................................................................#........#.............................#....................#..
 | 
				
			||||||
 | 
					..........#.....#...............................#..............................................................#...................#........
 | 
				
			||||||
 | 
					.........................................................#..................................................................................
 | 
				
			||||||
 | 
					.....................#......#.......................#.......................................................................................
 | 
				
			||||||
 | 
					.....................................#.....#.......................#.........................#...........#..............#..................#
 | 
				
			||||||
 | 
					...................................................................................................#........................................
 | 
				
			||||||
 | 
					...............#........................................................#.........................................#............#............
 | 
				
			||||||
 | 
					#........................................................................................#..................................................
 | 
				
			||||||
 | 
					...............................................................................#............................................................
 | 
				
			||||||
 | 
					....................................................#......#.........#..........................#...........................................
 | 
				
			||||||
 | 
					...............................................#.....................................................#...........................#..........
 | 
				
			||||||
 | 
					.....#............#........................................................................................................................#
 | 
				
			||||||
 | 
					...........................................#.................................................................#......#.......................
 | 
				
			||||||
 | 
					............#....................#...............................#..........#...............................................................
 | 
				
			||||||
 | 
					............................................................#......................................#........................#...............
 | 
				
			||||||
 | 
					...........................#.......................................................#..........#......................................#......
 | 
				
			||||||
 | 
					...................#..............................................................................................#.........................
 | 
				
			||||||
 | 
					....................................................................#......................................................................#
 | 
				
			||||||
 | 
					.............#................................#.............................................................................................
 | 
				
			||||||
 | 
					........#.........................#..........................................#..................#...........................................
 | 
				
			||||||
 | 
					...........................................................................................................#...............#................
 | 
				
			||||||
 | 
					........................................#.........#.......#.....................................................#...........................
 | 
				
			||||||
 | 
					..#................................................................................#.................................#.............#........
 | 
				
			||||||
 | 
					.....................#......#.......................................................................#.......................................
 | 
				
			||||||
 | 
					........................................................................................................................................#...
 | 
				
			||||||
 | 
					..........#.....#........................................................#............#......................................#..............
 | 
				
			||||||
 | 
					.....................................................#.......#..............................................................................
 | 
				
			||||||
 | 
					.............................................................................................................#.........#....................
 | 
				
			||||||
 | 
					...#.............................................................#........................................................................#.
 | 
				
			||||||
 | 
					.............................#.........#.................#.......................#.................#........................................
 | 
				
			||||||
 | 
					..............................................#.........................#...................#...............................................
 | 
				
			||||||
 | 
					............#............#..........................#.......................................................................................
 | 
				
			||||||
 | 
					....................................................................................................................#.......................
 | 
				
			||||||
 | 
					...................#...............................................#........................................................................
 | 
				
			||||||
 | 
					...................................#............#..........................................................#..............#.....#......#....
 | 
				
			||||||
 | 
					.......................#......#...........................................#..............#.........#........................................
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					..#............................................................#.....#...............................................#......................
 | 
				
			||||||
 | 
					.......#......................................#.........#.....................................................#..........................#..
 | 
				
			||||||
 | 
					.........................#...............................................................................#..................................
 | 
				
			||||||
 | 
					.............#...............................................................................#..............................................
 | 
				
			||||||
 | 
					#........................................#..................#.............#.........#.................................................#.....
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					..................................................#........................................................................................#
 | 
				
			||||||
 | 
					........#.............#............#...........................................................................#............................
 | 
				
			||||||
 | 
					..............#.....................................................................................#.......................................
 | 
				
			||||||
 | 
					...................................................................................................................#........................
 | 
				
			||||||
 | 
					..................#...........#............#................#...................................#..............................#............
 | 
				
			||||||
 | 
					......................................................................#.................#....................#.......................#......
 | 
				
			||||||
 | 
					.................................................................................#.........................................#................
 | 
				
			||||||
 | 
					............#....................................#......#...................................................................................
 | 
				
			||||||
 | 
					......................#.........................................#...........................................................................
 | 
				
			||||||
 | 
					.......#....................#.........#....................................................#.......................#............#...........
 | 
				
			||||||
 | 
					.............................................................................#......................#.......................................
 | 
				
			||||||
 | 
					...#.............#..........................#........#...............#...................................#................#.................
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					.................................................................................................#..........................................
 | 
				
			||||||
 | 
					.........................#.....#..................................................#...........................................#.......#.....
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					............#.....................................................#...............................................................#.........
 | 
				
			||||||
 | 
					...#........................#.................#.........................................................#...........#.....................#.
 | 
				
			||||||
 | 
					................#....................................#......................................#...............................................
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					............................................................................................................................................
 | 
				
			||||||
 | 
					...................................#.................................................#.................................#....................
 | 
				
			||||||
 | 
					.............#..............................#....................................................#..............#.......................#...
 | 
				
			||||||
 | 
					...................................................#.........#..........#..................#................................................
 | 
				
			||||||
 | 
					#......#.............#.......#...........................................................................#..................................
 | 
				
			||||||
 | 
					.................................................................................#..................#...............#.......................
 | 
				
			||||||
 | 
					..........................................................#.................................................................................
 | 
				
			||||||
 | 
					.......................................................................................................................................#....
 | 
				
			||||||
 | 
					...........#....................................................#......................#...................#................................
 | 
				
			||||||
 | 
					.......................................#................................#...................................................................
 | 
				
			||||||
 | 
					...................#............................................................................................#........#..........#.......
 | 
				
			||||||
 | 
					............................................#....................................................#......#.....................#.............
 | 
				
			||||||
 | 
					........#........................#................#...............#.........................................................................
 | 
				
			||||||
 | 
					.............#.............#............................................................#............................#......................
 | 
				
			||||||
 | 
					...........................................................#................................................................................
 | 
				
			||||||
 | 
					........................................#......#.............................#...............................#..............................
 | 
				
			||||||
 | 
					................#...........................................................................................................................
 | 
				
			||||||
 | 
					.................................................................#................#.................#.......................................
 | 
				
			||||||
 | 
					......#.............#...........#.....................................................................................................#.....
 | 
				
			||||||
 | 
					.#.......................#...........#......#.............................................#.................................................
 | 
				
			||||||
 | 
					........................................................#.................#.................................................................
 | 
				
			||||||
 | 
					....................................................................................#.......................................................
 | 
				
			||||||
 | 
					...............#..................#.............................#............................#..............#...............#...............
 | 
				
			||||||
 | 
					.........................................#.......................................................................#..........................
 | 
				
			||||||
 | 
					..#........#........#..............................#........................................................................................
 | 
				
			||||||
 | 
					............................................................#.....................#.........................................................
 | 
				
			||||||
 | 
					....................................#........................................#...........#......#......#....................................
 | 
				
			||||||
 | 
					.......................#.......................#..................................................................................#.........
 | 
				
			||||||
 | 
					........#......#.........................................................................................................................#..
 | 
				
			||||||
 | 
					..........................................................#..............................................................#..................
 | 
				
			||||||
 | 
					...#........................#........................#................#......................#......................#.......................
 | 
				
			||||||
 | 
					................................................................#..........#...........#......................................#.............
 | 
				
			||||||
 | 
					..............................................#.....................................................#.................................#.....
 | 
				
			||||||
 | 
					......................................#.....................................................................................................
 | 
				
			||||||
 | 
					..........#......#...............................................................................................#..........................
 | 
				
			||||||
 | 
					...........................................#.................#...................#........................................#.................
 | 
				
			||||||
 | 
					........................................................................................#......#...........................................#
 | 
				
			||||||
 | 
					....................................................................#.......................................................................
 | 
				
			||||||
 | 
					.#.......................#................................#..............#.............................................#....................
 | 
				
			||||||
 | 
					................................................#...............................................................#...........................
 | 
				
			||||||
 | 
					.......................................#.............#.....................................................#...............#................
 | 
				
			||||||
 | 
					.............#................#...................................................................#................................#........
 | 
				
			||||||
 | 
					.............................................#..........................................#.................................................#.
 | 
				
			||||||
 | 
					.................#................................................................#.........................................................
 | 
				
			||||||
 | 
					.#..........................................................................................................................................
 | 
				
			||||||
 | 
					........................................................................................................................#...................
 | 
				
			||||||
 | 
					...........#..........#...........#..............#.......................................................#.......#....................#.....
 | 
				
			||||||
 | 
					....#................................................................#......................................................................
 | 
				
			||||||
 | 
					...........................................#.................#...............................................#..................#...........
 | 
				
			||||||
 | 
					.....................................#....................................#..........#..........#...........................................
 | 
				
			||||||
 | 
					.........................................................................................................................#..............#...
 | 
				
			||||||
 | 
					.................................................................................#.........#............#...................................
 | 
				
			||||||
 | 
					................#......#.............................#.............#........................................................................
 | 
				
			||||||
 | 
					#.......#....................#.........#....................................................................................................
 | 
				
			||||||
 | 
					.............................................#..............................#.....................................................#.........
 | 
				
			||||||
 | 
					...................#.................................................................#......................................................
 | 
				
			||||||
 | 
					....................................#................................................................#..............#.......................
 | 
				
			||||||
 | 
					...................................................#...........#................................#...........#..............................#
 | 
				
			||||||
 | 
					.........................................................................#.....#............................................................
 | 
				
			||||||
 | 
					..#.....................#......................#.................................................................#...........#..............
 | 
				
			||||||
 | 
					.........................................................................................#.........#........................................
 | 
				
			||||||
 | 
					.........#.......................................................................................................................#......#...
 | 
				
			||||||
 | 
					.............................#.....#............................#.....#..............#...............................#......................
 | 
				
			||||||
 | 
					.............#.............................................#.............................................#.................#................
 | 
				
			||||||
							
								
								
									
										10
									
								
								2023/11/input_example.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								2023/11/input_example.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					...#......
 | 
				
			||||||
 | 
					.......#..
 | 
				
			||||||
 | 
					#.........
 | 
				
			||||||
 | 
					..........
 | 
				
			||||||
 | 
					......#...
 | 
				
			||||||
 | 
					.#........
 | 
				
			||||||
 | 
					.........#
 | 
				
			||||||
 | 
					..........
 | 
				
			||||||
 | 
					.......#..
 | 
				
			||||||
 | 
					#...#.....
 | 
				
			||||||
		Loading…
	
		Reference in a new issue