You've already forked advent_of_code
feat: Redo of the AoC repo starting over with 2015 and keeping up with
2025 (completed day 2 so far)
This commit is contained in:
BIN
25/1/__pycache__/main.cpython-313.pyc
Normal file
BIN
25/1/__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
BIN
25/1/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
BIN
25/1/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
Binary file not shown.
59
25/1/main.py
Normal file
59
25/1/main.py
Normal file
@@ -0,0 +1,59 @@
|
||||
'''AoC 2025 Day 1'''
|
||||
import math
|
||||
|
||||
def turn_dial(curr_pos: int, instruction: str) -> int:
|
||||
'''Turn dial from current position to the new one'''
|
||||
direction, amount = process_instruction(instruction)
|
||||
|
||||
new_pos = (curr_pos + (direction * amount)) % 100
|
||||
|
||||
return new_pos
|
||||
|
||||
|
||||
def check_cross_zero(curr_pos: int, instruction: str) -> int:
|
||||
'''Check for if the instruction crosses 0 and lands on it'''
|
||||
direction, amount = process_instruction(instruction)
|
||||
|
||||
total_zeros = 0
|
||||
|
||||
if direction == 1 and curr_pos + amount >= 100:
|
||||
total_zeros += math.floor((curr_pos + amount) / 100)
|
||||
if direction == -1 and curr_pos - amount <= 0:
|
||||
total_zeros += math.floor(abs((curr_pos - amount) / 100))
|
||||
if curr_pos != 0:
|
||||
total_zeros += 1
|
||||
|
||||
return total_zeros
|
||||
|
||||
|
||||
def process_instruction(instruction: str) -> (int, int):
|
||||
'''Returns the direction and amount of the turn'''
|
||||
direction = -1 if instruction[0] == 'L' else 1
|
||||
amount = int(instruction[1:])
|
||||
|
||||
return direction, amount
|
||||
|
||||
|
||||
def main():
|
||||
'''Entrypoint'''
|
||||
curr_pos = 50
|
||||
|
||||
num_zero = 0
|
||||
crossing_zero = 0
|
||||
|
||||
with open('input.txt', encoding='utf-8') as fh:
|
||||
for line in fh:
|
||||
crossing_zero += check_cross_zero(curr_pos, line.strip())
|
||||
|
||||
curr_pos = turn_dial(curr_pos, line.strip())
|
||||
|
||||
if curr_pos == 0:
|
||||
num_zero += 1
|
||||
|
||||
print(f'Part1: {num_zero}')
|
||||
|
||||
print(f'Part2: {crossing_zero}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
41
25/1/test_main.py
Normal file
41
25/1/test_main.py
Normal file
@@ -0,0 +1,41 @@
|
||||
'''testing'''
|
||||
import pytest
|
||||
|
||||
from main import turn_dial, check_cross_zero
|
||||
|
||||
@pytest.mark.parametrize('current, given, expected',
|
||||
[
|
||||
(50, 'L68', 82),
|
||||
(82, 'L30', 52),
|
||||
(52, 'R48', 0),
|
||||
(0, 'L5', 95),
|
||||
(95, 'R60', 55),
|
||||
(55, 'L55', 0),
|
||||
(0, 'L1', 99),
|
||||
(99, 'L99', 0),
|
||||
(0, 'R14', 14),
|
||||
(14, 'L82', 32),
|
||||
(50, 'R1000', 50),
|
||||
(50, 'L1000', 50)
|
||||
])
|
||||
def test_matching_zero(current, given, expected):
|
||||
assert turn_dial(current, given) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('current, given, expected',
|
||||
[
|
||||
(50, 'L68', 1),
|
||||
(82, 'L30', 0),
|
||||
(52, 'R48', 1),
|
||||
(0, 'L5', 0),
|
||||
(95, 'R60', 1),
|
||||
(55, 'L55', 1),
|
||||
(0, 'L1', 0),
|
||||
(99, 'L99', 1),
|
||||
(0, 'R14', 0),
|
||||
(14, 'L82', 1),
|
||||
(50, 'R1000', 10),
|
||||
(50, 'L1000', 10)
|
||||
])
|
||||
def test_crossing_zero(current, given, expected):
|
||||
assert check_cross_zero(current, given) == expected
|
||||
BIN
25/2/__pycache__/main.cpython-313.pyc
Normal file
BIN
25/2/__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
BIN
25/2/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
BIN
25/2/__pycache__/test_main.cpython-313-pytest-9.0.1.pyc
Normal file
Binary file not shown.
48
25/2/main.py
Normal file
48
25/2/main.py
Normal file
@@ -0,0 +1,48 @@
|
||||
'''AoC Day 2'''
|
||||
import re
|
||||
|
||||
def part1(range_list: list) -> int:
|
||||
'''Part 1'''
|
||||
total = 0
|
||||
|
||||
for id_range in range_list:
|
||||
for x in range(int(id_range[0]), int(id_range[1]) + 1):
|
||||
if not check_valid_id(str(x)):
|
||||
total += x
|
||||
|
||||
return total
|
||||
|
||||
def part2(range_list: list) -> int:
|
||||
'''Part 2'''
|
||||
total = 0
|
||||
|
||||
for id_range in range_list:
|
||||
for x in range(int(id_range[0]), int(id_range[1]) + 1):
|
||||
if not check_extended_id(str(x)):
|
||||
total += x
|
||||
|
||||
return total
|
||||
|
||||
def check_valid_id(id: str) -> bool:
|
||||
'''Checks a given ID for validity using the silly rules'''
|
||||
return re.fullmatch(r'(.*?)\1', id) is None
|
||||
|
||||
def check_extended_id(id: str) -> bool:
|
||||
'''Checks for extended rule checking, at least two repeats'''
|
||||
return re.fullmatch(r'(.*?)\1+', id) is None
|
||||
|
||||
def main():
|
||||
'''Entrypoint'''
|
||||
with open('input.txt', encoding='utf-8') as fh:
|
||||
range_list = [(y[0].strip(), y[1].strip()) for y in (x.split('-') for x in fh.readline().split(','))]
|
||||
|
||||
total = part1(range_list)
|
||||
|
||||
print(f'Part1: {total}')
|
||||
|
||||
total2 = part2(range_list)
|
||||
|
||||
print(f'Part2: {total2}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
87
25/2/test_main.py
Normal file
87
25/2/test_main.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import pytest
|
||||
|
||||
from main import check_valid_id, check_extended_id, part1, part2
|
||||
|
||||
@pytest.mark.parametrize('given, expected',
|
||||
[
|
||||
('1', True),
|
||||
('11', False),
|
||||
('12', True),
|
||||
('22', False),
|
||||
('1010', False),
|
||||
('1012', True),
|
||||
('1188511885', False),
|
||||
('222222', False),
|
||||
('446446', False),
|
||||
('565656', True),
|
||||
('446447', True),
|
||||
('38593859', False),
|
||||
('385385385', True)
|
||||
])
|
||||
def test_check_valid_id(given, expected):
|
||||
assert check_valid_id(given) == expected
|
||||
|
||||
@pytest.mark.parametrize('given, expected',
|
||||
[
|
||||
('1', True),
|
||||
('12', True),
|
||||
('1012', True),
|
||||
('446447', True),
|
||||
('11', False),
|
||||
('22', False),
|
||||
('99', False),
|
||||
('111', False),
|
||||
('999', False),
|
||||
('1010', False),
|
||||
('1188511885', False),
|
||||
('222222', False),
|
||||
('446446', False),
|
||||
('565656', False),
|
||||
('38593859', False),
|
||||
('385385385', False),
|
||||
('824824824', False),
|
||||
('2121212121', False)
|
||||
])
|
||||
def test_extended_valid_id(given, expected):
|
||||
assert check_extended_id(given) == expected
|
||||
|
||||
@pytest.mark.parametrize('given, expected',
|
||||
[
|
||||
(
|
||||
[
|
||||
('11', '22'),
|
||||
('95', '115'),
|
||||
('998', '1012'),
|
||||
('1188511880', '1188511890'),
|
||||
('222220', '222224'),
|
||||
('1698522', '1698528'),
|
||||
('446443', '446449'),
|
||||
('38593856', '38593862')
|
||||
],
|
||||
1227775554
|
||||
)
|
||||
])
|
||||
def test_part1_examples(given, expected):
|
||||
assert part1(given) == expected
|
||||
|
||||
@pytest.mark.parametrize('given, expected',
|
||||
[
|
||||
(
|
||||
[
|
||||
('11', '22'),
|
||||
('95', '115'),
|
||||
('998', '1012'),
|
||||
('1188511880', '1188511890'),
|
||||
('222220', '222224'),
|
||||
('1698522', '1698528'),
|
||||
('446443', '446449'),
|
||||
('38593856', '38593862'),
|
||||
('565653', '565659'),
|
||||
('824824821', '824824827'),
|
||||
('2121212118', '2121212124')
|
||||
],
|
||||
4174379265
|
||||
)
|
||||
])
|
||||
def test_part2_examples(given, expected):
|
||||
assert part2(given) == expected
|
||||
Reference in New Issue
Block a user