From 64388e38810953850a11c80f746f02785d118954 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 20 Jul 2021 12:53:28 -0500 Subject: [PATCH] add second part of solution 1 --- 2020/1/sample_input | 6 ++++++ 2020/1/solution.py | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 2020/1/sample_input diff --git a/2020/1/sample_input b/2020/1/sample_input new file mode 100644 index 0000000..e3fb011 --- /dev/null +++ b/2020/1/sample_input @@ -0,0 +1,6 @@ +1721 +979 +366 +299 +675 +1456 diff --git a/2020/1/solution.py b/2020/1/solution.py index f6c75a2..47c1273 100644 --- a/2020/1/solution.py +++ b/2020/1/solution.py @@ -2,12 +2,23 @@ fd = open("input", "r") lines = fd.readlines() +lines = [i.rstrip() for i in lines] mustbreak = False -for i in lines: - for j in lines: - if int(i) + int(j) == 2020: - print("{} * {} == {}".format(int(i), int(j), int(i) * int(j))) - mustbreak = True - break - if mustbreak: break +def part1(): + for i in lines: + for j in lines: + if int(i) + int(j) == 2020: + print("{} * {} = {}".format(int(i), int(j), int(i) * int(j))) + return + +def part2(): + for i in lines: + for j in lines: + for k in lines: + if int(i) + int(j) + int(k) == 2020: + print("{} * {} * {} = {}".format(int(i), int(j), int(k), int(i) * int(j) * int(k))) + return + +part1() +part2()