generated from public/aoc_template
Day 1
This commit is contained in:
parent
e1d3558c50
commit
ccefb7e6f0
47
day01.py
Normal file
47
day01.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
NUMBERS = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(142, "input1_test1"),
|
||||||
|
(53386, "input1"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(281, "input1_test2"),
|
||||||
|
(53312, "input1"),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
def getCalibrationSum(self, translate: bool = False) -> int:
|
||||||
|
calibration_sum = 0
|
||||||
|
for line in self.getInput():
|
||||||
|
dig = ""
|
||||||
|
while line:
|
||||||
|
if translate:
|
||||||
|
for i, n in enumerate(NUMBERS):
|
||||||
|
if line.startswith(n):
|
||||||
|
dig += str(i)
|
||||||
|
|
||||||
|
if ord("0") <= ord(line[0]) <= ord("9"):
|
||||||
|
dig += line[0]
|
||||||
|
|
||||||
|
line = line[1:]
|
||||||
|
|
||||||
|
calibration_sum += int(dig[0]) * 10 + int(dig[-1])
|
||||||
|
|
||||||
|
return calibration_sum
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
return self.getCalibrationSum()
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
return self.getCalibrationSum(True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
day = Day(2023, 1)
|
||||||
|
day.run(verbose=True)
|
||||||
1000
inputs/input1
Normal file
1000
inputs/input1
Normal file
File diff suppressed because it is too large
Load Diff
4
inputs/input1_test1
Normal file
4
inputs/input1_test1
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
||||||
7
inputs/input1_test2
Normal file
7
inputs/input1_test2
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
two1nine
|
||||||
|
eightwothree
|
||||||
|
abcone2threexyz
|
||||||
|
xtwone3four
|
||||||
|
4nineeightseven2
|
||||||
|
zoneight234
|
||||||
|
7pqrstsixteen
|
||||||
15
start_day.py
15
start_day.py
@ -29,11 +29,6 @@ if exists(day_file):
|
|||||||
print(day_file, "already exists. Use that one!")
|
print(day_file, "already exists. Use that one!")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
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)))
|
|
||||||
|
|
||||||
start = datetime(YEAR, 12, DAY, 6, 0, 0)
|
start = datetime(YEAR, 12, DAY, 6, 0, 0)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if start > now:
|
if start > now:
|
||||||
@ -43,9 +38,15 @@ if start > now:
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
for x in range(time_wait.seconds, -1, -1):
|
for x in range(time_wait.seconds, -1, -1):
|
||||||
print("Day starts in %02ds.\r")
|
print("Day starts in %02ds.\r" % x)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
call([CHARMS[system()], day_file])
|
|
||||||
webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY))
|
webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY))
|
||||||
|
|
||||||
|
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])
|
call(["git", "add", day_file])
|
||||||
|
call([CHARMS[system()], day_file])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user