diff --git a/2024/8/8.py b/2024/8/8.py new file mode 100644 index 0000000..54e1d9d --- /dev/null +++ b/2024/8/8.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# 2024 - Advent Of Code 8 + +# 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) + +def find_antinode(s, dest): + print(f'from {s} considering {dest}') + res = [] + diff_x = dest[0] - s[0] + diff_y = dest[1] - s[1] + # print(f'{diff_x}, {diff_y}') + + p1 = (dest[0] + diff_x, dest[1] + diff_y) + if 0 <= p1[0] < MAX_X and 0 <= p1[1] < MAX_Y: + res.append(p1) + + p2 = (s[0] - diff_x, s[1] - diff_y) + if 0 <= p2[0] < MAX_X and 0 <= p2[1] < MAX_Y: + res.append(p2) + + return res + +antennas = {} +freq = '' +for y in range(0, MAX_Y): + for x in range(0, MAX_X): + if input_lines[y][x] != '.': + freq = input_lines[y][x] + # print(f'found {freq=}') + if freq in antennas: + l = antennas[freq] + l.append((x, y)) + else: + antennas[freq] = [(x, y)] + +antinodes = set() +for freq, antennas_list in antennas.items(): + print(f'\nfreq {freq} list: {antennas_list}') + for antenna in antennas_list: + for other in antennas_list: + if other != antenna: + for a in find_antinode(antenna, other): + antinodes.add(a) + +print(f'{antinodes=}') +print(f'{len(antinodes)}') diff --git a/2024/8/input.txt b/2024/8/input.txt new file mode 100644 index 0000000..8430fd1 --- /dev/null +++ b/2024/8/input.txt @@ -0,0 +1,50 @@ +...........6.b.................................... +........6................8........................ +..Y.......................................o....... +....V...j............B.............c.............. +............8.........X.......L................... +.....j..v6.......3.L..................c........... +..Mj.....p3.......b........Z....................J. +..........M...X................................... +V..............v......p.........Z.........c....... +..............3................................... +.......V......U3.............c.................... +..........b..v.M.U8............................... +..........j........8.....................J........ +..........Y......q........LH..Z...D...........y... +..2Y........PX......6..................BQ......... +...0.Y...............XP...........w............... +.........U.......2...............oH.y............. +0..............9........U......................... +...........P..............W.......z...Oy.......... +...................t...p.W..o.............Q....... +.....S.................t.....Q....B............... +S.k..................V..W...p.......H...O......m.. +....S.h................W.......................O.. +..h..P.2.............Z.............J.............. +.........k.......5v.......q...t.s................. +.....Q.....h..........................J...B....... +........0.........l............................... +.S................................................ +.............................M.................... +2..................e.....o.....y.................. +................k................................. +......4......k....t...s.q......................... +.4.......................q........................ +.......................z....E..................... +.............0.....d.............................. +7..........D........z............................. +.......D..5......7..9............................. +......5..................E........................ +D..............K......d..9E..........w.....1..C... +.......K..x.........d....s...........l............ +........7......................u...C.............. +..K........x..............9..C...u................ +4..............s.........................l...T..w. +.......5.....7..................m......T......1... +...........................E...z.m................ +......................................u...C....... +.............................em................... +..............................................T... +....................x.......................e..... +.............................1e....w....l......... diff --git a/2024/8/input_example.txt b/2024/8/input_example.txt new file mode 100644 index 0000000..78a1e91 --- /dev/null +++ b/2024/8/input_example.txt @@ -0,0 +1,12 @@ +............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............