problems 1 + 2

This commit is contained in:
Stefan Harmuth 2025-03-19 09:36:17 +01:00
parent 834a510b0f
commit aed206e1e1
9 changed files with 760 additions and 169 deletions

View File

@ -1,17 +0,0 @@
repos:
- repo: https://github.com/LiquidFun/aoc_tiles
rev: 0.6.2
hooks:
- id: aoc-tiles
# Optionally use these arguments. Auto add tiles to git adds the tiles to git,
# possibly amends your commit by creating the tile images and updating the README.
# Language sorting shows the preference of the order of the languages to use.
# Exclude paterns are globs which can be used to exclude files when creating
# the tiles. See the customization section in the README for more flags.
# Simply remove the comments (#) below for args and the flags you want.
args:
- --auto-add-tiles-to-git=add
- --contrast-improvement-type=dark
- --overwrite-year=2024
# - --language-sorting=py,jl,kt,rs
# - --exclude-patterns=2021/*/*.apl,2021/*/*.py,2021/*/*.cpp

View File

@ -1,29 +1 @@
# aoc_template
Template for yearly AoC-Repositories
# Usage
- Clone repository (or use as template in gitea)
- Run `pip install -r requirements.txt`
- Update main.py and start_day.py: set YEAR (near the top) to the respective year
- Create a file named ".session" next to your main.py containing the contents of your aoc-session cookie
On a given day, just call `./start_day.py -d <day_of_month>`
# Not using PyCharm?
Just comment out the call() to CHARMS near the end of start_day.py
# Want to add AoC-Tiles?
Author: https://github.com/LiquidFun/aoc_tiles
- Run `pre-commit install --hook-type post-commit`
- In .pre-commit-config.yaml change the --overwrite-year option as needed
- Optional: Copy your .session file to session.cookie
- For more options see: https://github.com/LiquidFun/aoc_tiles/blob/main/aoc_tiles/config.py
Tiles will be added to this README between the following lines:
<!-- AOC TILES BEGIN -->
<!-- AOC TILES END -->
# Codyssi 2025 Journey to Atlantis

601
inputs/input1 Normal file
View File

@ -0,0 +1,601 @@
9
8
9
4
7
9
1
5
5
5
2
9
8
9
6
6
1
7
7
1
2
3
5
8
7
5
5
6
9
9
4
9
4
1
4
4
5
7
9
4
4
7
9
3
4
8
2
9
1
1
8
7
5
6
7
5
5
3
1
8
4
3
1
1
7
1
5
8
1
9
7
4
8
9
3
6
3
2
2
9
7
9
5
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3
9
7
9
8
-+-++--++----++-+++-+------+---+----++--++-++----+++++--++++++++-++--++--+--+----++--+--++-+-++-+-++--+++-++--++---+++--++--++-++++--+-++-+--+-+-+-----++++-+-+++++-+--+++++-++++-+-+-+++--+----+--+-+-+---+-+--++++------++-++-+-------+---+++++-----+-+-+++-+++---+---+++--++-+++----++-+++---++-++--+++++-++--+-+-+-+---+-+-++-++---+--+++-+++-+----++++---++-+-+-+++---+-+-+--+-++-+--+++-----++--+++-+++-+--+--++--+++-+---+----+----++-+++---++++-+++++++-+++-++++-++++-+--+-----+--+++-++++++-++--+--+----+++-+-+--+--++--++---+-+-+--++++-+-++++++---+-++-+--+--++---+-+++++++----+++--------+-+--+++-+++--++++

105
inputs/input2 Normal file
View File

@ -0,0 +1,105 @@
Function A: ADD 426
Function B: MULTIPLY 65
Function C: RAISE TO THE POWER OF 3
3267
8809
4378
7706
9260
8478
1359
5536
6885
1543
7785
4652
7835
5611
9961
5078
8655
8528
4923
3560
9469
1198
6587
3615
8560
8357
7244
2669
3791
5753
2945
3870
8299
1837
1074
4389
8457
3931
5995
3470
4184
6082
1261
3007
1328
4955
2369
8456
4869
8580
4021
5845
1535
6569
5068
5625
1457
9159
1455
3278
5125
4457
6232
6212
8248
1526
8198
6158
6978
9148
1737
3236
1326
3521
8234
1763
7300
4732
8541
2127
6178
9496
9407
2778
7576
8226
8210
6491
8626
6517
7309
5447
1058
6932
1871
8908
7429
5188
6026
1026
9183

41
main.py
View File

@ -1,41 +0,0 @@
#!/usr/bin/env python3
import tools.aoc
import argparse
import importlib
import os
YEAR = 2018
TIMEIT_NUMBER = 50
argument_parser = argparse.ArgumentParser()
argument_parser.add_argument("-d", "--day", help="specify day to process; leave empty for ALL days", type=int)
argument_parser.add_argument("-p", "--part", help="run only part x", choices=[1, 2], type=int)
argument_parser.add_argument("--timeit", help="measure execution time", action="store_true", default=False)
argument_parser.add_argument(
"--timeit-number",
help="build average time over this many executions",
type=int,
default=TIMEIT_NUMBER
)
argument_parser.add_argument("-v", "--verbose", help="show test case outputs", action="store_true", default=False)
flags = argument_parser.parse_args()
import_day = ""
if flags.day:
import_day = "%02d" % flags.day
imported = []
for _, _, files in os.walk(tools.aoc.BASE_PATH):
for f in files:
if f.startswith('day' + import_day) and f.endswith('.py'):
lib_name = f[:-3]
globals()[lib_name] = importlib.import_module(lib_name)
imported.append(lib_name)
break
for lib in sorted(imported):
day = int(lib[-2:])
day_class = getattr(globals()[lib], "Day")(YEAR, day)
day_class.run(flags.part if flags.part else 3, flags.verbose, flags.timeit, flags.timeit_number)

21
problem1.py Normal file
View File

@ -0,0 +1,21 @@
my_input = open("inputs/input1", "r").read().splitlines()
signs = my_input[-1]
p1 = int(my_input[0])
p2 = p1
p3 = p1 * 10 + int(my_input[1])
my_input = list(map(int, my_input[1:-1]))
for i, c in enumerate(signs):
p1 = p1 + my_input[i] if c == '+' else p1 - my_input[i]
p2 = p2 + my_input[-(i+1)] if c == '+' else p2 - my_input[-(i+1)]
signs = "".join(reversed(signs))
my_input = my_input[1:]
for i in range(0, len(my_input), 2):
num = my_input[i] * 10 + my_input[i+1]
p3 = p3 + num if signs[i//2] == '+' else p3 - num
print(p1)
print(p2)
print(p3)

32
problem2.py Normal file
View File

@ -0,0 +1,32 @@
my_input = open("inputs/input2", "r").read().splitlines()
func_a_add = int(my_input[0].split(": ")[1].split()[-1])
func_b_mul = int(my_input[1].split(": ")[1].split()[-1])
func_c_pow = int(my_input[2].split(": ")[1].split()[-1])
def expo_price(price: int) -> int:
price **= func_c_pow
price *= func_b_mul
price += func_a_add
return price
my_input = list(sorted(map(int, my_input[4:])))
p1 = my_input[len(my_input)//2]
p2 = 0
for x in my_input:
if x % 2 == 0:
p2 += x
p3 = 0
p3_max = 15_000_000_000_000
for x in my_input:
price = expo_price(x)
if price > p3 and price <= p3_max:
p3 = x
print(expo_price(p1))
print(expo_price(p2))
print(p3)

View File

@ -1,24 +0,0 @@
from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(None, "input%DAY%"),
],
[
(None, "input%DAY%"),
]
]
def part1(self) -> Any:
return ""
def part2(self) -> Any:
return ""
if __name__ == '__main__':
day = Day(%YEAR%, %DAY%)
day.run(verbose=True)

View File

@ -1,58 +0,0 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
from datetime import datetime
from os.path import exists
from platform import system
from subprocess import call
from time import sleep
from tools.tools import human_readable_time_from_delta
import webbrowser
YEAR = 2018
CHARMS = {
'Linux': '/usr/local/bin/charm',
'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd'
}
arg_parser = ArgumentParser()
arg_parser.add_argument("-d", "--day", help="start a specific day (default: today)", type=int)
args = arg_parser.parse_args()
DAY = args.day or datetime.now().day
if YEAR < 2015 or not 1 <= DAY <= 25:
print("Invalid year or day for year: %d, day: %d" % (YEAR, DAY))
exit()
day_file = "day%02d.py" % DAY
if exists(day_file):
print(day_file, "already exists. Use that one!")
exit()
start = datetime(YEAR, 12, DAY, 6, 0, 0)
now = datetime.now()
if start > now:
time_wait = start - now
if time_wait.days > 0:
print("Do you really want to wait %d days?" % time_wait.days)
exit()
while time_wait.seconds > 0:
print("Day %d starts in %s.\r" % (DAY, human_readable_time_from_delta(time_wait)))
if time_wait.seconds > 70:
wait = min(1, time_wait.seconds // 3600) * 3600 + min(1, time_wait.seconds // 60) * 60
sleep(wait)
else:
sleep(1)
time_wait = start - datetime.now()
with open("skel_day.py", "r") as IN:
with open(day_file, "w") as OUT:
while in_line := IN.readline():
OUT.write(in_line.replace("%YEAR%", str(YEAR)).replace("%DAY%", str(DAY)))
call(["git", "add", day_file])
webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY))
call([CHARMS[system()], day_file])