day 1
This commit is contained in:
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Python-generated files
|
||||
__pycache__/
|
||||
*.py[oc]
|
||||
build/
|
||||
dist/
|
||||
wheels/
|
||||
*.egg-info
|
||||
|
||||
# Virtual environments
|
||||
.venv
|
||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.14
|
||||
10
day-1-test.txt
Normal file
10
day-1-test.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
57
day-1.py
Normal file
57
day-1.py
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
class SafeBreaker:
|
||||
def __init__(self):
|
||||
self.value = 50
|
||||
self.times_pointing_zero = 0
|
||||
|
||||
def move_dial(self, instruction: str) -> None:
|
||||
direction = instruction[0]
|
||||
multiplier = -1 if direction == "L" else 1
|
||||
|
||||
movement = int(instruction[1:])
|
||||
self.times_pointing_zero += int(movement / 100)
|
||||
|
||||
movement_value = multiplier * (movement % 100)
|
||||
|
||||
# Move
|
||||
original_value = self.value
|
||||
self.value = self.value + movement_value
|
||||
|
||||
if self.value < 0:
|
||||
if original_value != 0:
|
||||
self.times_pointing_zero += 1
|
||||
print("past 0")
|
||||
self.value = 100 + self.value
|
||||
elif self.value >= 100:
|
||||
print("past 0")
|
||||
self.times_pointing_zero += 1
|
||||
self.value = self.value % 100
|
||||
elif self.value == 0:
|
||||
self.times_pointing_zero += 1
|
||||
|
||||
|
||||
def get_password(self) -> int:
|
||||
return self.times_pointing_zero
|
||||
|
||||
def crack_safe(self, instructions: list[str]) -> int:
|
||||
for instruction in instructions:
|
||||
self.move_dial(instruction)
|
||||
print(instruction, self.value)
|
||||
|
||||
return self.get_password()
|
||||
|
||||
if __name__ == "__main__":
|
||||
instructions = []
|
||||
|
||||
with open("./day-1.txt", "r") as file:
|
||||
for line in file.readlines():
|
||||
instructions.append(line.strip())
|
||||
|
||||
sb = SafeBreaker()
|
||||
password = sb.crack_safe(instructions)
|
||||
|
||||
print(password)
|
||||
|
||||
|
||||
|
||||
|
||||
6
main.py
Normal file
6
main.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def main():
|
||||
print("Hello from aoc-2025!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7
pyproject.toml
Normal file
7
pyproject.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[project]
|
||||
name = "aoc-2025"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.14"
|
||||
dependencies = []
|
||||
Reference in New Issue
Block a user