diff options
Diffstat (limited to '20/py')
| -rw-r--r-- | 20/py/aoc20.py | 43 | ||||
| -rw-r--r-- | 20/py/d01.py | 6 | ||||
| -rw-r--r-- | 20/py/d02.py | 6 | ||||
| -rw-r--r-- | 20/py/d03.py | 4 | ||||
| -rw-r--r-- | 20/py/d04.py | 6 | ||||
| -rw-r--r-- | 20/py/d05.py | 6 | ||||
| -rw-r--r-- | 20/py/d06.py | 6 | ||||
| -rw-r--r-- | 20/py/d07.py | 7 | ||||
| -rw-r--r-- | 20/py/d08.py | 6 | ||||
| -rw-r--r-- | 20/py/d09.py | 6 | ||||
| -rw-r--r-- | 20/py/driver.py | 32 |
11 files changed, 67 insertions, 61 deletions
diff --git a/20/py/aoc20.py b/20/py/aoc20.py new file mode 100644 index 0000000..3bd8994 --- /dev/null +++ b/20/py/aoc20.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import sys +import time + + +def read_input(args, day): + if len(args) > 0: + if args[0] == "-": + return sys.stdin.readlines() + else: + return open(args[0]).readlines() + else: + return open(f"../input/{day:02}", "r").readlines() + + +if __name__ == "__main__": + import d01 + import d02 + import d03 + import d04 + import d05 + import d06 + import d07 + import d08 + import d09 + + print("day part | time | tot_time | ans") + print("---------+--------+----------+-----------") + + time_to_here = 0 + for day, mod in enumerate((d01, d02, d03, d04, d05, + d06, d07, d08, d09)): + input = open(f"../input/{day+1:02}").readlines() + for part, part_func in enumerate((mod.pt1, mod.pt2)): + times = [] + for i in range(100 if "time" in sys.argv else 5): + start = time.time() + ans = part_func(input) + ans_time = time.time() + times.append(ans_time-start) + avg_time = sum(times) / len(times) + time_to_here += avg_time + print(f"{day+1:02} {part+1} | {avg_time*1000:6.3f} | {time_to_here*1000:6.3f} | {ans}") diff --git a/20/py/d01.py b/20/py/d01.py index c8ca64b..932f370 100644 --- a/20/py/d01.py +++ b/20/py/d01.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +import aoc20 +import sys + + def pt1(_in): nums = [int(n) for n in _in] for i, n1 in enumerate(nums): @@ -19,6 +23,6 @@ def pt2(_in): if __name__ == "__main__": - input = open("../input/01", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 1) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d02.py b/20/py/d02.py index 572404e..1ec2b8f 100644 --- a/20/py/d02.py +++ b/20/py/d02.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +import aoc20 +import sys + + def pt1(_in): valid = 0 for passwd in _in: @@ -27,6 +31,6 @@ def pt2(_in): if __name__ == "__main__": - input = open("../input/02", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 2) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d03.py b/20/py/d03.py index 40b6b6c..4b4fe5b 100644 --- a/20/py/d03.py +++ b/20/py/d03.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys @@ -51,7 +52,6 @@ def pt2(_in): if __name__ == "__main__": - input = open("../input/03", "r").readlines() - #input = [line for line in sys.stdin] + input = aoc20.read_input(sys.argv[1:], 3) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d04.py b/20/py/d04.py index d0387f6..8162335 100644 --- a/20/py/d04.py +++ b/20/py/d04.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys @@ -92,9 +93,6 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/04", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 4) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d05.py b/20/py/d05.py index d72d3ee..28f637e 100644 --- a/20/py/d05.py +++ b/20/py/d05.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys @@ -43,9 +44,6 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/05", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 5) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d06.py b/20/py/d06.py index 8604b00..586463c 100644 --- a/20/py/d06.py +++ b/20/py/d06.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys @@ -36,9 +37,6 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/06", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 6) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d07.py b/20/py/d07.py index 775b7c8..1d25e53 100644 --- a/20/py/d07.py +++ b/20/py/d07.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys import regex as re import functools @@ -43,11 +44,7 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/07", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 7) # graph(parse(input)) - print(pt1(input)) print(pt2(input)) diff --git a/20/py/d08.py b/20/py/d08.py index d435ea2..dd9535a 100644 --- a/20/py/d08.py +++ b/20/py/d08.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys @@ -46,9 +47,6 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/08", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 8) print(pt1(input)) print(pt2(input)) diff --git a/20/py/d09.py b/20/py/d09.py index 9950f16..3094c94 100644 --- a/20/py/d09.py +++ b/20/py/d09.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import aoc20 import sys from collections import deque @@ -45,9 +46,6 @@ def pt2(_in): if __name__ == "__main__": - if len(sys.argv) > 1: - input = open(sys.argv[1], "r").readlines() - else: - input = open("../input/09", "r").readlines() + input = aoc20.read_input(sys.argv[1:], 9) print(pt1(input)) print(pt2(input)) diff --git a/20/py/driver.py b/20/py/driver.py deleted file mode 100644 index 8b0fa03..0000000 --- a/20/py/driver.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 -import sys -import time - -import d01 -import d02 -import d03 -import d04 -import d05 -import d06 -import d07 -import d08 -import d09 - - -print("day part | time | tot_time | ans") -print("---------+--------+----------+-----------") - -time_to_here = 0 -for day, mod in enumerate((d01, d02, d03, d04, d05, - d06, d07, d08, d09)): - input = open(f"../input/{day+1:02}").readlines() - for part, part_func in enumerate((mod.pt1, mod.pt2)): - times = [] - for i in range(100 if "time" in sys.argv else 5): - start = time.time() - ans = part_func(input) - ans_time = time.time() - times.append(ans_time-start) - avg_time = sum(times) / len(times) - time_to_here += avg_time - print(f"{day+1:02} {part+1} | {avg_time*1000:6.3f} | {time_to_here*1000:6.3f} | {ans}") |
