From 4b2ef3bfbda1121523aeb2055ff79a7babde7472 Mon Sep 17 00:00:00 2001 From: The Myth <72611306+TheMyth1710@users.noreply.github.com> Date: Tue, 12 Jul 2022 20:56:35 +0530 Subject: [PATCH] Update 1.py --- 2020/1.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/2020/1.py b/2020/1.py index 0ecd49e..33f502e 100644 --- a/2020/1.py +++ b/2020/1.py @@ -1,27 +1,28 @@ -data = [] # Your Advent Input +data = [] # Your Advent Input as a proper list. +# Recommended to run this for input: +with open(location,'r') as f: #Replace location with the input.txt file location of your Advent Input + data = f.readlines() + f.close() data = [o.rstrip('\n') for o in data] del data[-1] def day1(part=1): done = False - # Part 1 if part not in [1,2]: part == 1 # Default Part - if part == 1: - for i in range(len(data)): - for j in range(len(data)): - if data[i] + data[j] == 2020: - return data[i]*data[j] + if part == 1: # Part 1 + for i in data: + for j in data: + if i + j == 2020: + return i*j done = True # To stop the code after retrieving first value. if done: break - - # Part 2 - elif part == 2: - for i in range(len(data)): - for j in range(len(data)): - for k in range(len(data)): - if data[i] + data[j] + data[k]== 2020: - return data[i]*data[j]*data[k] + elif part == 2: # Part 2 + for i in data: + for j in data: + for k in data: + if i + j + k == 2020: + return i*j*k done = True # To stop the code after retrieving first value. if done: break