prep 2019 + day01 solve
This commit is contained in:
commit
b50168fd3b
23
day01.py
Normal file
23
day01.py
Normal file
@ -0,0 +1,23 @@
|
||||
from aoc import AOCDay
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
test_solutions_p1 = [2, 2, 654, 33583]
|
||||
test_solutions_p2 = [2, 966, 50346]
|
||||
|
||||
def part1(self):
|
||||
fuel_sum = 0
|
||||
for x in self.getInputListAsType(int):
|
||||
fuel_sum += x // 3 - 2
|
||||
|
||||
return fuel_sum
|
||||
|
||||
def part2(self):
|
||||
fuel_sum = 0
|
||||
for x in self.getInputListAsType(int):
|
||||
fuel_add = x // 3 - 2
|
||||
while fuel_add > 0:
|
||||
fuel_sum += fuel_add
|
||||
fuel_add = fuel_add // 3 - 2
|
||||
|
||||
return fuel_sum
|
||||
100
inputs/input01
Normal file
100
inputs/input01
Normal file
@ -0,0 +1,100 @@
|
||||
54032
|
||||
64433
|
||||
71758
|
||||
133884
|
||||
76994
|
||||
99596
|
||||
90491
|
||||
89188
|
||||
142280
|
||||
127352
|
||||
62127
|
||||
79849
|
||||
96049
|
||||
56527
|
||||
148029
|
||||
81386
|
||||
149827
|
||||
105377
|
||||
91970
|
||||
98708
|
||||
88611
|
||||
99785
|
||||
99229
|
||||
88460
|
||||
80396
|
||||
70097
|
||||
91784
|
||||
81733
|
||||
75671
|
||||
106787
|
||||
77196
|
||||
132234
|
||||
98698
|
||||
115243
|
||||
119574
|
||||
142851
|
||||
58964
|
||||
137814
|
||||
127695
|
||||
92139
|
||||
106277
|
||||
51240
|
||||
121351
|
||||
78316
|
||||
129472
|
||||
65201
|
||||
116068
|
||||
72803
|
||||
52582
|
||||
135433
|
||||
87619
|
||||
68096
|
||||
116952
|
||||
106437
|
||||
70517
|
||||
69840
|
||||
89863
|
||||
134618
|
||||
83823
|
||||
113436
|
||||
103779
|
||||
134819
|
||||
107928
|
||||
138503
|
||||
82509
|
||||
90104
|
||||
98001
|
||||
76202
|
||||
136238
|
||||
66426
|
||||
74030
|
||||
55075
|
||||
124163
|
||||
57133
|
||||
79908
|
||||
109977
|
||||
66903
|
||||
125400
|
||||
130961
|
||||
149293
|
||||
99203
|
||||
120307
|
||||
142403
|
||||
50262
|
||||
52854
|
||||
70851
|
||||
142213
|
||||
77567
|
||||
149144
|
||||
144582
|
||||
58138
|
||||
61765
|
||||
116209
|
||||
128192
|
||||
137436
|
||||
101406
|
||||
69037
|
||||
107389
|
||||
112389
|
||||
124402
|
||||
1
inputs/test_input01_1_0
Normal file
1
inputs/test_input01_1_0
Normal file
@ -0,0 +1 @@
|
||||
12
|
||||
1
inputs/test_input01_1_1
Normal file
1
inputs/test_input01_1_1
Normal file
@ -0,0 +1 @@
|
||||
14
|
||||
1
inputs/test_input01_1_2
Normal file
1
inputs/test_input01_1_2
Normal file
@ -0,0 +1 @@
|
||||
1969
|
||||
1
inputs/test_input01_1_3
Normal file
1
inputs/test_input01_1_3
Normal file
@ -0,0 +1 @@
|
||||
100756
|
||||
1
inputs/test_input01_2_0
Normal file
1
inputs/test_input01_2_0
Normal file
@ -0,0 +1 @@
|
||||
14
|
||||
1
inputs/test_input01_2_1
Normal file
1
inputs/test_input01_2_1
Normal file
@ -0,0 +1 @@
|
||||
1969
|
||||
1
inputs/test_input01_2_2
Normal file
1
inputs/test_input01_2_2
Normal file
@ -0,0 +1 @@
|
||||
100756
|
||||
79
main.py
Normal file
79
main.py
Normal file
@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import aoc
|
||||
import argparse
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
import timeit
|
||||
|
||||
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("-t", "--test", help="run test cases", action="store_true", default=False)
|
||||
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
|
||||
)
|
||||
flags = argument_parser.parse_args()
|
||||
|
||||
import_day = ""
|
||||
if flags.day:
|
||||
import_day = "%02d" % flags.day
|
||||
|
||||
imported = []
|
||||
for _, _, files in os.walk(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")(day)
|
||||
if not flags.test:
|
||||
if not flags.part or flags.part == 1:
|
||||
if not day_class.test_part1(silent=True):
|
||||
print("TEST FAILED! Aborting.")
|
||||
sys.exit(1)
|
||||
|
||||
if not flags.part or flags.part == 2:
|
||||
if not day_class.test_part2(silent=True):
|
||||
print("TEST FAILED! Aborting.")
|
||||
sys.exit(1)
|
||||
|
||||
if not flags.part or flags.part == 1:
|
||||
if not flags.timeit:
|
||||
if flags.test:
|
||||
day_class.test_part1()
|
||||
else:
|
||||
aoc.printSolution(day, 1, day_class.part1())
|
||||
else:
|
||||
exec_time = timeit.timeit(
|
||||
'day_class.part1()',
|
||||
globals=globals(),
|
||||
number=flags.timeit_number
|
||||
) / flags.timeit_number
|
||||
aoc.printSolution(day, 1, day_class.part1(), exec_time=exec_time)
|
||||
|
||||
if not flags.part or flags.part == 2:
|
||||
if not flags.timeit:
|
||||
if flags.test:
|
||||
day_class.test_part2()
|
||||
else:
|
||||
aoc.printSolution(day, 2, day_class.part2())
|
||||
else:
|
||||
exec_time = timeit.timeit(
|
||||
'day_class.part2()',
|
||||
globals=globals(),
|
||||
number=flags.timeit_number
|
||||
) / flags.timeit_number
|
||||
aoc.printSolution(day, 2, day_class.part2(), exec_time=exec_time)
|
||||
13
skel_day.py
Normal file
13
skel_day.py
Normal file
@ -0,0 +1,13 @@
|
||||
from aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
test_solutions_p1 = []
|
||||
test_solutions_p2 = []
|
||||
|
||||
def part1(self) -> Any:
|
||||
return ""
|
||||
|
||||
def part2(self) -> Any:
|
||||
return ""
|
||||
Loading…
Reference in New Issue
Block a user