From 1b6af5adf3f711f0cfb71c820183af92276c42d4 Mon Sep 17 00:00:00 2001 From: kleph Date: Fri, 6 Dec 2024 12:42:47 +0100 Subject: [PATCH] 2024 - Day 6 part 1 --- 2024/6/6.py | 51 +++++++++++++++ 2024/6/input.txt | 130 +++++++++++++++++++++++++++++++++++++++ 2024/6/input_example.txt | 10 +++ 3 files changed, 191 insertions(+) create mode 100644 2024/6/6.py create mode 100644 2024/6/input.txt create mode 100644 2024/6/input_example.txt diff --git a/2024/6/6.py b/2024/6/6.py new file mode 100644 index 0000000..daf7082 --- /dev/null +++ b/2024/6/6.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# 2024 - Advent Of Code 6 + +# 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")] + +MAX_X = len(input_lines[0]) +MAX_Y = len(input_lines) + +vector=(0, 0) +gx = 0 +gy = 0 +for y in range(0, MAX_Y): + for x in range(0, MAX_X): + g = input_lines[y][x] + if g not in ('.', '#'): + gx = x + gy = y + print(f'found guard at {x}, {y}') + if g == '^': + vector = (0, -1) + if g == 'v': + vector = (0, 1) + if g == '>': + vector = (1, 0) + if g == '<': + vector = (-1, 0) + print(f'{vector=}') + +moves = [(0,-1), (1, 0), (0, 1), (-1, 0)] +move = moves.index(vector) + +visited = set() +visited.add((gx, gy)) +while 0 < gx < MAX_X and 0 < gy < MAX_Y: + nextx = gx + vector[0] + nexty = gy + vector[1] + if nextx < 0 or nextx >= MAX_X or nexty < 0 or nexty >= MAX_Y: + break + if input_lines[nexty][nextx] != '#': + gx += vector[0] + gy += vector[1] + visited.add((gx, gy)) + else: + move += 1 + vector = moves[move % 4] + +print(f'{len(visited)=}') diff --git a/2024/6/input.txt b/2024/6/input.txt new file mode 100644 index 0000000..d0b0d37 --- /dev/null +++ b/2024/6/input.txt @@ -0,0 +1,130 @@ +........#...#..................#.#............#....#....##.........#.............................................#................ +.#...............#...........................#..........#..........#....#........................................#............#... +............#...........................................##.................#.......#............................................#. +...#.......................##.........................................#..............................................#....#....... +.......#....#......#...................................#............#............#.......#.......#.................#.............. +#......#........#..................................#..##........#...........#.....................#......#..................#..... +......................#........#.....#.....................#.......##........#............#.#....#..#.......#..................... +#.........................#.................#.............................................................#....................... +.....#....#.................................#........#..#.........................#............#...#.........#...#..............## +......................................................................................#...#......................#...#...#..#..... +.................#........#.............................#........................#.....#..................#....................... +...#.........................#.#..........#.....#..............................#..#...#...#.........#............................. +.#............#.................#.....#..............#................#...........................................#............... +...........#...#......#.........##................#...................................................#....#.#.................... +.................................#..................................................#..............................#...#.......... +.#...............#............#....................................#.....................#............#....................#.....# +.#....#.....................#.....#.......................#......#......#...................................#.....#.........#...#. +.............#...#...............................#...#...........#...............#....#....#..............................#....... +...#......................................................................#.........................................#............. +...#..................................#........#........#...................#.............#....................................... +......................................................................................................................#........#.. +......................#.....................................#.....#.................#.........#..............#............#....... +..........................#...................#....................................................................#........#..... +...........#.....................................................#............#.....................#....................#........ +..............................#.....#......................................#..........#...#........#........................#..... +.......................................#..................#.........#..#....................................................#..#.. +........................................................................#.................##..#................................... +................#.#.....................#.......#..#..................#.........#................................................. +........#......#......................#.........#..........................................#..........#....#..##....#.......#..... +......................................#..........#...........................#..................................#......#.......... +..##...#..#......................#............................#...................#........#...................................... +.......#........#............#..................#....#...##....................................................................... +....#......................#......#.............#................................#...#........#.........#.....................#..# +......................#...#.........................#..................................###..............................#........# +.....................................................................................#.....#...............#.......#.............. +............#.................................#..................#..........................................#.................#... +..........#...................................#.............................#..........#................................#......... +............................#..........................................................................#....#.............#....... +...............#..#.........#.................................................................##........................#.......#. +.............#..........................................................................#......................................... +........................................#...#...#....................#...........#...........#.................................... +............................#................#..............#............................#.......#..#............................. +................#...#.........#.............#.........#.......#...........................................#..#.....#.............. +.......#......#.#.............................................#.....#...#...........#............................................. +.#....#...............#.........................#....................#........#..................................................# +..........................................................#.................#.................................#...........##...... +....#.....................................#..........................#........#.....#........................#.................... +...##................................#........................................#..............#.....................#...#..#....#.. +..............#.......#..................................#..................#.....................#....#.....................#.... +.......................#......................................##..........#......#..............#.............................#... +....#....................#............#.........................................................................................#. +..........#..#.......#.....................#................#.#.....#.....#...........................#........................... +.......................#..#.#.............................................#......#..........#..................................... +...........#.........................................................................#..............#..............#.............. +............................................................#..................................................................... +...................#....#..#..............#...........................................................#.......#.#................. +..............#...#.#....#......#...........................................................................................#....# +....................#.................................................................................#..#...#.................... +.......#...#...................#.............................................#..............###..........#........................ +...................................#................#.........................................................................#... +..............#.......................#...................................#................................#...................... +...........................##........................#...............................#.........#.................................. +....................................................#..........##.......................................................#......... +........................#................................##.................##.#...........................#.....................# +..............................................................................................................#................... +.............................#........#..........................#................................................................ +..........#..........#...............................................#...#................#......................................# +................#...........#...............................................................................#................#.... +.....................#.............................................................................#..#................#.....#.... +#.................#....#.......................................#..........................#...###.......#..#.....#.#..#..........# +............................................................^.............................#.#............................##....#.. +.#............#.................#......#..................................#....................##................................. +......................................................................#.......#...............#..................#..........#..... +.........................................#............................................#.....#.#.#..#..........................#... +....................#.........................................................#.......#...#..#.....#.............................. +..........#......................................................##......#................#.....................#................. +..........#.............................#..........................#...........#..#............................................... +.................................#......#.............##...............................................................#.......... +........................................................................#.....#.....................##...##...........#........... +..#..#.................................#......................#.........#.................#.......................##.............. +.....................................#..........................................................#................................. +...................#...........#..........#............................#.........#................................................ +................#................................................................................................................. +........................................#.....................##.......#........#................#....#................#.......... +.................#.............#........................#..................................#...................................... +......#............................#.......................................................#.....#........#.....#..............#.. +..........#..................................#.......................#............................................................ +...#..................................................#...........#....#....#.......................#.........................#... +............................................#..#............................#..................#......#........#...........#..#... +#........................#........................................................#............................................... +.....#.#.#................................................##.#...................................#.....................#.#........ +....#................#..............#.....................................................#........#................#............. +..........#........#...................................................#...........................#.............................. +....................#..#.........................#....#.......#....##.............#............................................... +.................#...........................#...........#................................#...........................#........... +......#...#....................................................................................................................#.. +......#.......#......................................#.........#.................#.#..........#.................................#. +.......#........................###.........................#...................#................#.................#.............. +.##.........#.........#..............................................#...........................................#..#.#.........#. +..........#..................#..........................................................#.....#..................#...............# +......................#..............#.....................##................#..#.....#..........................#.#.............. +....#.#..#..............................#........#........................................................................#....... +.........................#.....................#....#.....................#..........................................#............ +..#..#........#........................#................................#..................................#.#..................#. +........#...#.....................##.........#.............................................................................#...... +....#...........#............................#.............................#...........#........#..............#..#............... +......#...................#................#..................................................##.......#....................#..... +.........#.##..................................................................................................................... +........................................#......................#................#....#......................#...........#......... +.#......#.#......#................#....#...#..............#...........#........................................#.................. +#...#......................................##.................................................................................#... +.................#.........#...............................#......#.................#.......................................#...#. +...#..#......#.........#...........#..............#...................................................................#.........#. +...........#.#........................................#..............#............................................................ +...........................#.................................................................................#............#....... +.............#......................................................#.................#..#..............#......................... +...........#.....................................................#...............................#................#....#.......... +..........#....#........................#...........................................................................#............. +.......................................................#..........................................#...................#........... +..............#...........................................#.............................#..................#...................... +.................#....................................................#.....................................#...............#..... +.......................................#........................#.........#................#........#............##.....#......... +....#...#..............#........................#....................#........#...................................#............... +......##.#......................................................................#.............#................................... +....#.......................#..........#..#..............#..............#.#..........................#...............#....#....... +.........................#......................#...........................#...............#......#.............#................ +.......#.........................#.......................................................................#........................ +.......................#........................................#...............##...........#...................#.....##...#..... +.....#........................#.............#.........#.....#................#..............#..........................#.......... +.................#...................#....#...........#....#........................##.....#...#.................................. diff --git a/2024/6/input_example.txt b/2024/6/input_example.txt new file mode 100644 index 0000000..a4eb402 --- /dev/null +++ b/2024/6/input_example.txt @@ -0,0 +1,10 @@ +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#...