From 8b035ab9b69c0a9e638a858a97dbe7c94032582b Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 1 Dec 2020 08:57:01 +0100 Subject: [PATCH] Day 1 --- 2020/day1.py | 20 ++++++++++++++++++++ 2020/skel.py.txt | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 2020/day1.py create mode 100644 2020/skel.py.txt diff --git a/2020/day1.py b/2020/day1.py new file mode 100644 index 0000000..40378f0 --- /dev/null +++ b/2020/day1.py @@ -0,0 +1,20 @@ +import itertools + + +def main(): + with open("day1.txt", "rt") as f: + lines = [line.rstrip() for line in f.readlines()] + values = list(map(lambda l: int(l), lines)) + + # Part 1 + for a, b in itertools.combinations(values, 2): + if a + b == 2020: + print(a * b) + # Part 2 + for a, b, c in itertools.combinations(values, 3): + if a + b + c == 2020: + print(a * b * c) + + +if __name__ == "__main__": + main() diff --git a/2020/skel.py.txt b/2020/skel.py.txt new file mode 100644 index 0000000..732477d --- /dev/null +++ b/2020/skel.py.txt @@ -0,0 +1,7 @@ +def main(): + with open("", "rt") as f: + lines = [line.rstrip() for line in f.readlines()] + + +if __name__ == "__main__": + main()