2025 lets goooo

This commit is contained in:
2025-12-01 11:42:09 +00:00
parent b95908d5fc
commit 841bdbcfd6
9 changed files with 235 additions and 137 deletions
+1
View File
@@ -0,0 +1 @@
3.14
+68
View File
@@ -0,0 +1,68 @@
testing = False
if not testing:
with open(r"2025/01/input.txt", "r") as file:
input = file.read()
else:
input = '''L68
L30
R48
L5
R60
L55
L1
L99
R14
L82'''
answer:int = 0
TEST_EXPECTED_ANSWER:int = 3
# make a list to simulate dial?
dial = [i for i in range(100)]
#print(dial)
direction = {
'L':'-=',
'R':'+='
}
position:int = 50
def perform_operation(value, operator, operand):
if operator == "+=":
return value + operand
elif operator == "-=":
return value - operand
else:
raise ValueError("Unsupported operator")
def move_dial(position, movement):
#print(movement)
direction_to_move = movement[0]
amount_to_move = movement[1:]
#print(direction_to_move)
#print(amount_to_move)
decide = direction[direction_to_move]
#print(decide)
new_position = perform_operation(int(position), decide, int(amount_to_move))
return new_position % 100
win_counter:int = 0
for step in input.split('\n'):
#print(position)
position = move_dial(position, step)
#print(position)
#print(dial[position])
if dial[position] == 0:
win_counter += 1
answer = win_counter
if testing:
if answer == TEST_EXPECTED_ANSWER:
print('test successful')
else:
print(f'wrong... expected {TEST_EXPECTED_ANSWER} received {answer}')
else:
print(answer)
+67
View File
@@ -0,0 +1,67 @@
testing = False
if not testing:
with open(r"2025/01/input.txt", "r") as file:
input = file.read()
else:
input = '''L68
L30
R48
L5
R60
L55
L1
L99
R14
L82'''
answer:int = 0
TEST_EXPECTED_ANSWER:int = 6
# make a list to simulate dial?
dial = [i for i in range(100)]
position:int = 50
zero_count: int = 0
def move_dial_with_zero_count(current_position, movement):
direction_to_move = movement[0]
amount_to_move = int(movement[1:])
# Determine the direction
if direction_to_move == 'L':
step = -1
elif direction_to_move == 'R':
step = 1
else:
raise ValueError("Invalid direction")
# Count how many times we hit 0 during this rotation
count = 0
current = current_position
# Go through each step of the rotation
for _ in range(amount_to_move):
current = (current + step) % 100
if current == 0:
count += 1
return current, count
# Process each step
for step in input.strip().split('\n'):
#print(f"Before: {position}")
position, zero_count_increment = move_dial_with_zero_count(position, step)
zero_count += zero_count_increment
#print(f"After: {position} (zero hits: {zero_count_increment})")
answer = zero_count
if testing:
if answer == TEST_EXPECTED_ANSWER:
print('test successful')
else:
print(f'wrong... expected {TEST_EXPECTED_ANSWER} received {answer}')
else:
print(answer)
View File
+3 -3
View File
@@ -84,15 +84,15 @@ def get_puzzle_part(year, day):
def create_solution_file(year, day, part):
folder = rf"{year}/{day:02}"
os.makedirs(folder, exist_ok=True)
solution_file = os.path.join(folder, f"part {part} solution.py")
solution_file = os.path.join(folder, f"part_{part}_solution.py")
input_file_path = os.path.join(folder, "input.txt")
# Check if the solution file already exists
if not os.path.exists(solution_file):
with open(solution_file, "w") as file:
file.write(f"""testing = 1
file.write(f"""testing = True
if not testing:
with open(r"{year}/{day:02}\input.txt", "r") as file:
with open(r"{year}/{day:02}/input.txt", "r") as file:
input = file.read()
else:
input = '''
-134
View File
@@ -1,134 +0,0 @@
import os
import requests
from datetime import datetime
class aoc:
def __init__(self, year, day):
self.year = year
self.day = day
self.folder = rf"{year}/{day:02}"
def get_puzzle_text(self):
with open(r'session_cookie.txt', 'r') as file:
session_cookie = file.read().strip()
url = f"https://adventofcode.com/{year}/day/{day}"
cookies = {'session': session_cookie}
response = requests.get(url, cookies=cookies)
response.raise_for_status()
return response.text
def get_puzzle_input(self):
with open(r'session_cookie.txt', 'r') as file:
session_cookie = file.read().strip()
url = f"https://adventofcode.com/{year}/day/{day}/input"
cookies = {'session': session_cookie}
response = requests.get(url, cookies=cookies)
response.raise_for_status()
# Remove the trailing newline
puzzle_input = response.text.strip()
return puzzle_input
def save_puzzle_text(self):
os.makedirs(self.folder, exist_ok=True)
input_file = os.path.join(self.folder, "puzzle_text.md")
puzzle_text = get_puzzle_text(self)
puzzle_text = puzzle_text.split('<main>')[1]
puzzle_text = puzzle_text.split('</article>')[0]
print(f'Saving puzzle text to {input_file}')
with open(input_file, "w") as file:
file.write(puzzle_text)
def save_puzzle_input(self):
os.makedirs(self.folder, exist_ok=True)
input_file = os.path.join(self.folder, "input.txt")
puzzle_input = get_puzzle_input(self)
print(f'Saving puzzle input to {input_file}')
with open(input_file, "w") as file:
file.write(puzzle_input)
def save_part_2_puzzle_text(self):
input_file = os.path.join(self.folder, "puzzle_text.md")
# grab the existing puzzle text
with open(input_file, "r") as file:
existing_puzzle_text = file.read()
# Check if part 2 has already been added
if "part2" in existing_puzzle_text:
print("There is nothing more to add... Idiot.")
return
puzzle_text = get_puzzle_text(self)
puzzle_text = puzzle_text.split('<main>')[1]
#get all the text after the first </article> tag
puzzle_text = puzzle_text.split('</article>')[1]
# Remove everything after the puzzle text which is all the things after the </article> tag
puzzle_text = puzzle_text.split('</article>')[0]
# Add the existing puzzle text back in
puzzle_text = existing_puzzle_text + puzzle_text
print(f'Saving puzzle text to {input_file}')
with open(input_file, "w") as file:
file.write(puzzle_text)
def get_puzzle_part(self):
# Check if the puzzle text for the day equals "# Day {day} Puzzle Text."
os.makedirs(self.folder, exist_ok=True)
input_file = os.path.join(self.folder, "puzzle_text.md")
# Create the file if it doesn't exist
if not os.path.isfile(input_file):
with open(input_file, "w") as file:
pass
# grab the existing puzzle text
with open(input_file, "r") as file:
existing_puzzle_text = file.read()
if not existing_puzzle_text: # == f"# Day {day} Puzzle Text.":
return 1
else:
return 2
def create_solution_file(self, part):
os.makedirs(self.folder, exist_ok=True)
solution_file = os.path.join(self.folder, f"part {part} solution.py")
input_file_path = os.path.join(self.folder, "input.txt")
# Check if the solution file already exists
if not os.path.exists(solution_file):
with open(solution_file, "w") as file:
file.write(f"""with open(r'{input_file_path}', 'r') as file:
input = file.read()
""")
print(f"Created {solution_file}")
else:
print(f"{solution_file} already exists. No action taken.")
# Usage example
current_year = datetime.now().year
current_day = datetime.now().day
def populate_data(year = current_year, day=current_day):
"""
Populates data for the Advent of Code puzzle.
Requires a session cookie to be saved in session_cookie.txt
This function checks if the puzzle text for the day equals "# Day {day} Puzzle Text."
If it does, it saves the puzzle text and input for part 1.
If not, it checks if part 2 has already been added to the puzzle text.
If part 2 has not been added, it saves the puzzle text for part 2.
Args:
year (int): The year of the Advent of Code puzzle. Defaults to the current year.
day (int): The day of the Advent of Code puzzle. Defaults to the current day.
Returns:
None
"""
part_check = get_puzzle_part(self)
if part_check == 1:
save_puzzle_text(self)
save_puzzle_input(self)
create_solution_file(year, day, part_check)
elif part_check == 2:
save_part_2_puzzle_text(self)
create_solution_file(year, day, part_check)
else:
print("Something went wrong. Check the puzzle text.")
populate_data()
+6
View File
@@ -0,0 +1,6 @@
def main():
print("Hello from advent-of-code!")
if __name__ == "__main__":
main()
+9
View File
@@ -0,0 +1,9 @@
[project]
name = "advent-of-code"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"requests>=2.32.5",
]
Generated
+81
View File
@@ -0,0 +1,81 @@
version = 1
revision = 3
requires-python = ">=3.14"
[[package]]
name = "advent-of-code"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "requests" },
]
[package.metadata]
requires-dist = [{ name = "requests", specifier = ">=2.32.5" }]
[[package]]
name = "certifi"
version = "2025.11.12"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/a2/8c/58f469717fa48465e4a50c014a0400602d3c437d7c0c468e17ada824da3a/certifi-2025.11.12.tar.gz", hash = "sha256:d8ab5478f2ecd78af242878415affce761ca6bc54a22a27e026d7c25357c3316", size = 160538, upload-time = "2025-11-12T02:54:51.517Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/70/7d/9bc192684cea499815ff478dfcdc13835ddf401365057044fb721ec6bddb/certifi-2025.11.12-py3-none-any.whl", hash = "sha256:97de8790030bbd5c2d96b7ec782fc2f7820ef8dba6db909ccf95449f2d062d4b", size = 159438, upload-time = "2025-11-12T02:54:49.735Z" },
]
[[package]]
name = "charset-normalizer"
version = "3.4.4"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/13/69/33ddede1939fdd074bce5434295f38fae7136463422fe4fd3e0e89b98062/charset_normalizer-3.4.4.tar.gz", hash = "sha256:94537985111c35f28720e43603b8e7b43a6ecfb2ce1d3058bbe955b73404e21a", size = 129418, upload-time = "2025-10-14T04:42:32.879Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/2a/35/7051599bd493e62411d6ede36fd5af83a38f37c4767b92884df7301db25d/charset_normalizer-3.4.4-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:da3326d9e65ef63a817ecbcc0df6e94463713b754fe293eaa03da99befb9a5bd", size = 207746, upload-time = "2025-10-14T04:41:33.773Z" },
{ url = "https://files.pythonhosted.org/packages/10/9a/97c8d48ef10d6cd4fcead2415523221624bf58bcf68a802721a6bc807c8f/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8af65f14dc14a79b924524b1e7fffe304517b2bff5a58bf64f30b98bbc5079eb", size = 147889, upload-time = "2025-10-14T04:41:34.897Z" },
{ url = "https://files.pythonhosted.org/packages/10/bf/979224a919a1b606c82bd2c5fa49b5c6d5727aa47b4312bb27b1734f53cd/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:74664978bb272435107de04e36db5a9735e78232b85b77d45cfb38f758efd33e", size = 143641, upload-time = "2025-10-14T04:41:36.116Z" },
{ url = "https://files.pythonhosted.org/packages/ba/33/0ad65587441fc730dc7bd90e9716b30b4702dc7b617e6ba4997dc8651495/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:752944c7ffbfdd10c074dc58ec2d5a8a4cd9493b314d367c14d24c17684ddd14", size = 160779, upload-time = "2025-10-14T04:41:37.229Z" },
{ url = "https://files.pythonhosted.org/packages/67/ed/331d6b249259ee71ddea93f6f2f0a56cfebd46938bde6fcc6f7b9a3d0e09/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d1f13550535ad8cff21b8d757a3257963e951d96e20ec82ab44bc64aeb62a191", size = 159035, upload-time = "2025-10-14T04:41:38.368Z" },
{ url = "https://files.pythonhosted.org/packages/67/ff/f6b948ca32e4f2a4576aa129d8bed61f2e0543bf9f5f2b7fc3758ed005c9/charset_normalizer-3.4.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ecaae4149d99b1c9e7b88bb03e3221956f68fd6d50be2ef061b2381b61d20838", size = 152542, upload-time = "2025-10-14T04:41:39.862Z" },
{ url = "https://files.pythonhosted.org/packages/16/85/276033dcbcc369eb176594de22728541a925b2632f9716428c851b149e83/charset_normalizer-3.4.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cb6254dc36b47a990e59e1068afacdcd02958bdcce30bb50cc1700a8b9d624a6", size = 149524, upload-time = "2025-10-14T04:41:41.319Z" },
{ url = "https://files.pythonhosted.org/packages/9e/f2/6a2a1f722b6aba37050e626530a46a68f74e63683947a8acff92569f979a/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c8ae8a0f02f57a6e61203a31428fa1d677cbe50c93622b4149d5c0f319c1d19e", size = 150395, upload-time = "2025-10-14T04:41:42.539Z" },
{ url = "https://files.pythonhosted.org/packages/60/bb/2186cb2f2bbaea6338cad15ce23a67f9b0672929744381e28b0592676824/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:47cc91b2f4dd2833fddaedd2893006b0106129d4b94fdb6af1f4ce5a9965577c", size = 143680, upload-time = "2025-10-14T04:41:43.661Z" },
{ url = "https://files.pythonhosted.org/packages/7d/a5/bf6f13b772fbb2a90360eb620d52ed8f796f3c5caee8398c3b2eb7b1c60d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:82004af6c302b5d3ab2cfc4cc5f29db16123b1a8417f2e25f9066f91d4411090", size = 162045, upload-time = "2025-10-14T04:41:44.821Z" },
{ url = "https://files.pythonhosted.org/packages/df/c5/d1be898bf0dc3ef9030c3825e5d3b83f2c528d207d246cbabe245966808d/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:2b7d8f6c26245217bd2ad053761201e9f9680f8ce52f0fcd8d0755aeae5b2152", size = 149687, upload-time = "2025-10-14T04:41:46.442Z" },
{ url = "https://files.pythonhosted.org/packages/a5/42/90c1f7b9341eef50c8a1cb3f098ac43b0508413f33affd762855f67a410e/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:799a7a5e4fb2d5898c60b640fd4981d6a25f1c11790935a44ce38c54e985f828", size = 160014, upload-time = "2025-10-14T04:41:47.631Z" },
{ url = "https://files.pythonhosted.org/packages/76/be/4d3ee471e8145d12795ab655ece37baed0929462a86e72372fd25859047c/charset_normalizer-3.4.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:99ae2cffebb06e6c22bdc25801d7b30f503cc87dbd283479e7b606f70aff57ec", size = 154044, upload-time = "2025-10-14T04:41:48.81Z" },
{ url = "https://files.pythonhosted.org/packages/b0/6f/8f7af07237c34a1defe7defc565a9bc1807762f672c0fde711a4b22bf9c0/charset_normalizer-3.4.4-cp314-cp314-win32.whl", hash = "sha256:f9d332f8c2a2fcbffe1378594431458ddbef721c1769d78e2cbc06280d8155f9", size = 99940, upload-time = "2025-10-14T04:41:49.946Z" },
{ url = "https://files.pythonhosted.org/packages/4b/51/8ade005e5ca5b0d80fb4aff72a3775b325bdc3d27408c8113811a7cbe640/charset_normalizer-3.4.4-cp314-cp314-win_amd64.whl", hash = "sha256:8a6562c3700cce886c5be75ade4a5db4214fda19fede41d9792d100288d8f94c", size = 107104, upload-time = "2025-10-14T04:41:51.051Z" },
{ url = "https://files.pythonhosted.org/packages/da/5f/6b8f83a55bb8278772c5ae54a577f3099025f9ade59d0136ac24a0df4bde/charset_normalizer-3.4.4-cp314-cp314-win_arm64.whl", hash = "sha256:de00632ca48df9daf77a2c65a484531649261ec9f25489917f09e455cb09ddb2", size = 100743, upload-time = "2025-10-14T04:41:52.122Z" },
{ url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl", hash = "sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f", size = 53402, upload-time = "2025-10-14T04:42:31.76Z" },
]
[[package]]
name = "idna"
version = "3.11"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/0703ccc57f3a7233505399edb88de3cbd678da106337b9fcde432b65ed60/idna-3.11.tar.gz", hash = "sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902", size = 194582, upload-time = "2025-10-12T14:55:20.501Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" },
]
[[package]]
name = "requests"
version = "2.32.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "certifi" },
{ name = "charset-normalizer" },
{ name = "idna" },
{ name = "urllib3" },
]
sdist = { url = "https://files.pythonhosted.org/packages/c9/74/b3ff8e6c8446842c3f5c837e9c3dfcfe2018ea6ecef224c710c85ef728f4/requests-2.32.5.tar.gz", hash = "sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf", size = 134517, upload-time = "2025-08-18T20:46:02.573Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6", size = 64738, upload-time = "2025-08-18T20:46:00.542Z" },
]
[[package]]
name = "urllib3"
version = "2.5.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/15/22/9ee70a2574a4f4599c47dd506532914ce044817c7752a79b6a51286319bc/urllib3-2.5.0.tar.gz", hash = "sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760", size = 393185, upload-time = "2025-06-18T14:07:41.644Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl", hash = "sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc", size = 129795, upload-time = "2025-06-18T14:07:40.39Z" },
]