From b0acd1d834a1282b2f1b66b67caf91b93cf5a80c Mon Sep 17 00:00:00 2001 From: kleph Date: Wed, 20 Mar 2024 05:26:03 +0100 Subject: [PATCH] 2023 - Day 11 part 1 --- 2023/11/11.py | 72 ++++++++++++++++++++ 2023/11/input.txt | 140 ++++++++++++++++++++++++++++++++++++++ 2023/11/input_example.txt | 10 +++ 3 files changed, 222 insertions(+) create mode 100644 2023/11/11.py create mode 100644 2023/11/input.txt create mode 100644 2023/11/input_example.txt diff --git a/2023/11/11.py b/2023/11/11.py new file mode 100644 index 0000000..40e086c --- /dev/null +++ b/2023/11/11.py @@ -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=}') diff --git a/2023/11/input.txt b/2023/11/input.txt new file mode 100644 index 0000000..c0fb56d --- /dev/null +++ b/2023/11/input.txt @@ -0,0 +1,140 @@ +.........................#.........#..................#..............#.......#.....#........................#............#.....#...........# +.............................................#.....................................................#........................................ +.......#............#..........#............................................................................................................ +.#................................................#........#.............................................#..............................#... +................#.....................#.............................................................................#....................... +........................................................................#....................#................#...........#................. +...........................................#........................................#....................................................... +..................................#......................#.......#...........#.............................................................. +..........#................................................................................................................................. +..............................................#..........................................#.....................................#............ +..........................................................................#................................................................. +...#................#...........#.......#............................#...............................#...................................... +.........................................................................................................................#.................. +.............................................................................#........#.............................#....................#.. +..........#.....#...............................#..............................................................#...................#........ +.........................................................#.................................................................................. +.....................#......#.......................#....................................................................................... +.....................................#.....#.......................#.........................#...........#..............#..................# +...................................................................................................#........................................ +...............#........................................................#.........................................#............#............ +#........................................................................................#.................................................. +...............................................................................#............................................................ +....................................................#......#.........#..........................#........................................... +...............................................#.....................................................#...........................#.......... +.....#............#........................................................................................................................# +...........................................#.................................................................#......#....................... +............#....................#...............................#..........#............................................................... +............................................................#......................................#........................#............... +...........................#.......................................................#..........#......................................#...... +...................#..............................................................................................#......................... +....................................................................#......................................................................# +.............#................................#............................................................................................. +........#.........................#..........................................#..................#........................................... +...........................................................................................................#...............#................ +........................................#.........#.......#.....................................................#........................... +..#................................................................................#.................................#.............#........ +.....................#......#.......................................................................#....................................... +........................................................................................................................................#... +..........#.....#........................................................#............#......................................#.............. +.....................................................#.......#.............................................................................. +.............................................................................................................#.........#.................... +...#.............................................................#........................................................................#. +.............................#.........#.................#.......................#.................#........................................ +..............................................#.........................#...................#............................................... +............#............#..........................#....................................................................................... +....................................................................................................................#....................... +...................#...............................................#........................................................................ +...................................#............#..........................................................#..............#.....#......#.... +.......................#......#...........................................#..............#.........#........................................ +............................................................................................................................................ +..#............................................................#.....#...............................................#...................... +.......#......................................#.........#.....................................................#..........................#.. +.........................#...............................................................................#.................................. +.............#...............................................................................#.............................................. +#........................................#..................#.............#.........#.................................................#..... +............................................................................................................................................ +..................................................#........................................................................................# +........#.............#............#...........................................................................#............................ +..............#.....................................................................................#....................................... +...................................................................................................................#........................ +..................#...........#............#................#...................................#..............................#............ +......................................................................#.................#....................#.......................#...... +.................................................................................#.........................................#................ +............#....................................#......#................................................................................... +......................#.........................................#........................................................................... +.......#....................#.........#....................................................#.......................#............#........... +.............................................................................#......................#....................................... +...#.............#..........................#........#...............#...................................#................#................. +............................................................................................................................................ +.................................................................................................#.......................................... +.........................#.....#..................................................#...........................................#.......#..... +............................................................................................................................................ +............#.....................................................#...............................................................#......... +...#........................#.................#.........................................................#...........#.....................#. +................#....................................#......................................#............................................... +............................................................................................................................................ +............................................................................................................................................ +...................................#.................................................#.................................#.................... +.............#..............................#....................................................#..............#.......................#... +...................................................#.........#..........#..................#................................................ +#......#.............#.......#...........................................................................#.................................. +.................................................................................#..................#...............#....................... +..........................................................#................................................................................. +.......................................................................................................................................#.... +...........#....................................................#......................#...................#................................ +.......................................#................................#................................................................... +...................#............................................................................................#........#..........#....... +............................................#....................................................#......#.....................#............. +........#........................#................#...............#......................................................................... +.............#.............#............................................................#............................#...................... +...........................................................#................................................................................ +........................................#......#.............................#...............................#.............................. +................#........................................................................................................................... +.................................................................#................#.................#....................................... +......#.............#...........#.....................................................................................................#..... +.#.......................#...........#......#.............................................#................................................. +........................................................#.................#................................................................. +....................................................................................#....................................................... +...............#..................#.............................#............................#..............#...............#............... +.........................................#.......................................................................#.......................... +..#........#........#..............................#........................................................................................ +............................................................#.....................#......................................................... +....................................#........................................#...........#......#......#.................................... +.......................#.......................#..................................................................................#......... +........#......#.........................................................................................................................#.. +..........................................................#..............................................................#.................. +...#........................#........................#................#......................#......................#....................... +................................................................#..........#...........#......................................#............. +..............................................#.....................................................#.................................#..... +......................................#..................................................................................................... +..........#......#...............................................................................................#.......................... +...........................................#.................#...................#........................................#................. +........................................................................................#......#...........................................# +....................................................................#....................................................................... +.#.......................#................................#..............#.............................................#.................... +................................................#...............................................................#........................... +.......................................#.............#.....................................................#...............#................ +.............#................#...................................................................#................................#........ +.............................................#..........................................#.................................................#. +.................#................................................................#......................................................... +.#.......................................................................................................................................... +........................................................................................................................#................... +...........#..........#...........#..............#.......................................................#.......#....................#..... +....#................................................................#...................................................................... +...........................................#.................#...............................................#..................#........... +.....................................#....................................#..........#..........#........................................... +.........................................................................................................................#..............#... +.................................................................................#.........#............#................................... +................#......#.............................#.............#........................................................................ +#.......#....................#.........#.................................................................................................... +.............................................#..............................#.....................................................#......... +...................#.................................................................#...................................................... +....................................#................................................................#..............#....................... +...................................................#...........#................................#...........#..............................# +.........................................................................#.....#............................................................ +..#.....................#......................#.................................................................#...........#.............. +.........................................................................................#.........#........................................ +.........#.......................................................................................................................#......#... +.............................#.....#............................#.....#..............#...............................#...................... +.............#.............................................#.............................................#.................#................ diff --git a/2023/11/input_example.txt b/2023/11/input_example.txt new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/2023/11/input_example.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#.....