chore: formatting

main
Cassie Cheung 6 months ago
parent 62d75050a6
commit 0f9b08288e
Signed by: cassie
GPG Key ID: 21918D0F2EEBCCD5
6 changed files with 56 additions and 14 deletions

@ -35,9 +35,13 @@ class InvalidDayWarning(UserWarning):
##### ADD STUFF BELOW HERE #####
################################
tmpl_m = """# copy and rename to main_2 for part 2.
tmpl_m = """from aoc_utils.log import debug
# copy and rename to main_2 for part 2.
def main(data: str):
debug("nothing here!")
... # write your logic here !
if __name__ == "__main__":
@ -49,7 +53,7 @@ if __name__ == "__main__":
tmpl_t = """from main{pt} import main
test_data = '''
paste in test data here
{testdata}
'''
main(test_data.strip())
@ -177,6 +181,12 @@ def new(ctx, day):
f"day {day} may not be available yet ({day} > today ({TODAY.day}))! proceed with caution and don't spam this."
)
echo("Paste in the test data:")
tests = ""
while (line := input("> ")) != "":
tests += line + "\n"
tests = tests.strip()
echo(f"Fetching puzzle input for day {day}...")
res = requests.get(
f"https://adventofcode.com/{config['year']}/day/{day}/input",
@ -196,8 +206,12 @@ def new(ctx, day):
os.makedirs(f'./{config["year"]}/{day}', exist_ok=True)
create_file(f'./{config["year"]}/{day}/input.txt', data)
create_file(f'./{config["year"]}/{day}/main.py', tmpl_m)
create_file(f'./{config["year"]}/{day}/test.py', tmpl_t.format(pt=""))
create_file(f'./{config["year"]}/{day}/test_2.py', tmpl_t.format(pt="_2"))
create_file(
f'./{config["year"]}/{day}/test.py', tmpl_t.format(pt="", testdata=tests)
)
create_file(
f'./{config["year"]}/{day}/test_2.py', tmpl_t.format(pt="_2", testdata=tests)
)
def main() -> int | None:
@ -205,5 +219,4 @@ def main() -> int | None:
if __name__ == "__main__":
echo(sys.path)
sys.exit(main())

@ -3,7 +3,7 @@ def main(data: str):
calories = {}
setn = len(sets) # number of sets
print(f"total sets: {setn}")
print(f"[DBG] sets: {sets}")
print(f"sets: {sets}")
for count, _set in enumerate(sets):
c_cals = 0

@ -23,15 +23,19 @@ def main(data: str):
strats = [(round.split()[0], round.split()[1]) for round in data.splitlines()]
for count, (opp, winlose) in enumerate(strats):
debug("###############################################")
debug(f"Opponent used {opp}, need to { {'X':'lose','Y':'tie','Z':'win'}.get(winlose) }")
debug(
f"Opponent used {opp}, need to { {'X':'lose','Y':'tie','Z':'win'}.get(winlose) }"
)
cur = 0
cur += scoring[winlose]
debug(f"{winlose}: +{scoring[winlose]} pt")
# figure out which shape to use
match winlose:
case "X": # Lose
debug(f"LOSE: base score of shape {rule[opp][2]} is {shapes[rule[opp][2]]}")
debug(
f"LOSE: base score of shape {rule[opp][2]} is {shapes[rule[opp][2]]}"
)
wl = 2
case "Y": # Draw
debug(f"DRAW: base score of {rule[opp][1]} is {shapes[rule[opp][1]]}")
@ -40,11 +44,13 @@ def main(data: str):
debug(f" WIN: base score of {rule[opp][0]} is {shapes[rule[opp][2]]}")
wl = 0
case _:
raise ValueError(f'what the fuck is {winlose}')
raise ValueError(f"what the fuck is {winlose}")
cur += shapes[rule[opp][wl]]
score += cur
print(f"Round #{count+1}: {shapes[rule[opp][wl]]} + {scoring[winlose]} = {cur}; Σ={score}")
print(
f"Round #{count+1}: {shapes[rule[opp][wl]]} + {scoring[winlose]} = {cur}; Σ={score}"
)
print("========== RESULT ==========")
print(f" total: {score}")

@ -1,4 +1,10 @@
def main(data):
from aoc_utils.log import debug
# copy and rename to main_2 for part 2.
def main(data: str):
debug("nothing here!")
... # write your logic here !

@ -1,7 +1,12 @@
from main import main
test_data = """
paste in test data here
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
"""
main(test_data.strip())

@ -0,0 +1,12 @@
from main_2 import main
test_data = """
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
"""
main(test_data.strip())
Loading…