2024 - Day 6 part 1
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kleph 2024-12-06 12:42:47 +01:00
parent 14260bfcfc
commit 1b6af5adf3
3 changed files with 191 additions and 0 deletions

51
2024/6/6.py Normal file
View file

@ -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)=}')

130
2024/6/input.txt Normal file
View file

@ -0,0 +1,130 @@
........#...#..................#.#............#....#....##.........#.............................................#................
.#...............#...........................#..........#..........#....#........................................#............#...
............#...........................................##.................#.......#............................................#.
...#.......................##.........................................#..............................................#....#.......
.......#....#......#...................................#............#............#.......#.......#.................#..............
#......#........#..................................#..##........#...........#.....................#......#..................#.....
......................#........#.....#.....................#.......##........#............#.#....#..#.......#.....................
#.........................#.................#.............................................................#.......................
.....#....#.................................#........#..#.........................#............#...#.........#...#..............##
......................................................................................#...#......................#...#...#..#.....
.................#........#.............................#........................#.....#..................#.......................
...#.........................#.#..........#.....#..............................#..#...#...#.........#.............................
.#............#.................#.....#..............#................#...........................................#...............
...........#...#......#.........##................#...................................................#....#.#....................
.................................#..................................................#..............................#...#..........
.#...............#............#....................................#.....................#............#....................#.....#
.#....#.....................#.....#.......................#......#......#...................................#.....#.........#...#.
.............#...#...............................#...#...........#...............#....#....#..............................#.......
...#......................................................................#.........................................#.............
...#..................................#........#........#...................#.............#.......................................
......................................................................................................................#........#..
......................#.....................................#.....#.................#.........#..............#............#.......
..........................#...................#....................................................................#........#.....
...........#.....................................................#............#.....................#....................#........
..............................#.....#......................................#..........#...#........#........................#.....
.......................................#..................#.........#..#....................................................#..#..
........................................................................#.................##..#...................................
................#.#.....................#.......#..#..................#.........#.................................................
........#......#......................#.........#..........................................#..........#....#..##....#.......#.....
......................................#..........#...........................#..................................#......#..........
..##...#..#......................#............................#...................#........#......................................
.......#........#............#..................#....#...##.......................................................................
....#......................#......#.............#................................#...#........#.........#.....................#..#
......................#...#.........................#..................................###..............................#........#
.....................................................................................#.....#...............#.......#..............
............#.................................#..................#..........................................#.................#...
..........#...................................#.............................#..........#................................#.........
............................#..........................................................................#....#.............#.......
...............#..#.........#.................................................................##........................#.......#.
.............#..........................................................................#.........................................
........................................#...#...#....................#...........#...........#....................................
............................#................#..............#............................#.......#..#.............................
................#...#.........#.............#.........#.......#...........................................#..#.....#..............
.......#......#.#.............................................#.....#...#...........#.............................................
.#....#...............#.........................#....................#........#..................................................#
..........................................................#.................#.................................#...........##......
....#.....................................#..........................#........#.....#........................#....................
...##................................#........................................#..............#.....................#...#..#....#..
..............#.......#..................................#..................#.....................#....#.....................#....
.......................#......................................##..........#......#..............#.............................#...
....#....................#............#.........................................................................................#.
..........#..#.......#.....................#................#.#.....#.....#...........................#...........................
.......................#..#.#.............................................#......#..........#.....................................
...........#.........................................................................#..............#..............#..............
............................................................#.....................................................................
...................#....#..#..............#...........................................................#.......#.#.................
..............#...#.#....#......#...........................................................................................#....#
....................#.................................................................................#..#...#....................
.......#...#...................#.............................................#..............###..........#........................
...................................#................#.........................................................................#...
..............#.......................#...................................#................................#......................
...........................##........................#...............................#.........#..................................
....................................................#..........##.......................................................#.........
........................#................................##.................##.#...........................#.....................#
..............................................................................................................#...................
.............................#........#..........................#................................................................
..........#..........#...............................................#...#................#......................................#
................#...........#...............................................................................#................#....
.....................#.............................................................................#..#................#.....#....
#.................#....#.......................................#..........................#...###.......#..#.....#.#..#..........#
............................................................^.............................#.#............................##....#..
.#............#.................#......#..................................#....................##.................................
......................................................................#.......#...............#..................#..........#.....
.........................................#............................................#.....#.#.#..#..........................#...
....................#.........................................................#.......#...#..#.....#..............................
..........#......................................................##......#................#.....................#.................
..........#.............................#..........................#...........#..#...............................................
.................................#......#.............##...............................................................#..........
........................................................................#.....#.....................##...##...........#...........
..#..#.................................#......................#.........#.................#.......................##..............
.....................................#..........................................................#.................................
...................#...........#..........#............................#.........#................................................
................#.................................................................................................................
........................................#.....................##.......#........#................#....#................#..........
.................#.............#........................#..................................#......................................
......#............................#.......................................................#.....#........#.....#..............#..
..........#..................................#.......................#............................................................
...#..................................................#...........#....#....#.......................#.........................#...
............................................#..#............................#..................#......#........#...........#..#...
#........................#........................................................#...............................................
.....#.#.#................................................##.#...................................#.....................#.#........
....#................#..............#.....................................................#........#................#.............
..........#........#...................................................#...........................#..............................
....................#..#.........................#....#.......#....##.............#...............................................
.................#...........................#...........#................................#...........................#...........
......#...#....................................................................................................................#..
......#.......#......................................#.........#.................#.#..........#.................................#.
.......#........................###.........................#...................#................#.................#..............
.##.........#.........#..............................................#...........................................#..#.#.........#.
..........#..................#..........................................................#.....#..................#...............#
......................#..............#.....................##................#..#.....#..........................#.#..............
....#.#..#..............................#........#........................................................................#.......
.........................#.....................#....#.....................#..........................................#............
..#..#........#........................#................................#..................................#.#..................#.
........#...#.....................##.........#.............................................................................#......
....#...........#............................#.............................#...........#........#..............#..#...............
......#...................#................#..................................................##.......#....................#.....
.........#.##.....................................................................................................................
........................................#......................#................#....#......................#...........#.........
.#......#.#......#................#....#...#..............#...........#........................................#..................
#...#......................................##.................................................................................#...
.................#.........#...............................#......#.................#.......................................#...#.
...#..#......#.........#...........#..............#...................................................................#.........#.
...........#.#........................................#..............#............................................................
...........................#.................................................................................#............#.......
.............#......................................................#.................#..#..............#.........................
...........#.....................................................#...............................#................#....#..........
..........#....#........................#...........................................................................#.............
.......................................................#..........................................#...................#...........
..............#...........................................#.............................#..................#......................
.................#....................................................#.....................................#...............#.....
.......................................#........................#.........#................#........#............##.....#.........
....#...#..............#........................#....................#........#...................................#...............
......##.#......................................................................#.............#...................................
....#.......................#..........#..#..............#..............#.#..........................#...............#....#.......
.........................#......................#...........................#...............#......#.............#................
.......#.........................#.......................................................................#........................
.......................#........................................#...............##...........#...................#.....##...#.....
.....#........................#.............#.........#.....#................#..............#..........................#..........
.................#...................#....#...........#....#........................##.....#...#..................................

10
2024/6/input_example.txt Normal file
View file

@ -0,0 +1,10 @@
....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...