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()