Skip to content

Commit

Permalink
Updated Files
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismudith committed Jul 13, 2022
1 parent 63c5820 commit 767aa23
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 22 deletions.
44 changes: 26 additions & 18 deletions 2020/1.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
# If you already have the data as an input use:
data = [] # Your Advent Input
# However, it is highly recommended to run this:
location = "" # Path of the input.txt provided from Advent Calendar
try:
with open(location,'r') as f:
data = f.readlines()
f.close()
except:
pass
data = [o.rstrip('\n') for o in data]
del data[-1]
if data[-1] == "'+":
del data[-1]
def day1(part=1):
done = False
# Part 1
if part not in [1,2]:
part == 1 # Default Part
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]
done = True # To stop the code after retrieving first value.
for i in data:
for j in data:
if int(i) + int(j) == 2020:
done = True
return int(i)*int(j)
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]
done = True # To stop the code after retrieving first value.
else: # Part 2
for i in data:
for j in data:
for k in data:
if int(i) + int(j) + int(k)== 2020:
done = True
return int(i)*int(j)*int(k)
if done:
break
if done:
break
print(day1(part=1))
print(day1(part=2))
print('Part 1: '+day1(part=1))
print('Part 2: '+day1(part=2))
18 changes: 14 additions & 4 deletions 2020/2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# If you already have the data as an input use:
data = [] # Your Advent Input
# However, it is highly recommended to run this:
location = "" # Path of the input.txt provided from Advent Calendar
try:
with open(location,'r') as f:
data = f.readlines()
f.close()
except:
pass
data = [o.rstrip('\n') for o in data]
del data[-1]
if data[-1] == "'+":
del data[-1]
def day2(part=1):
count = 0
if part not in [1,2]:
part == 1 #Default Part
part = 1 #Default Part
for i in data:
i = i.split(' ')
start = int(i[0].split('-')[0])
Expand All @@ -17,5 +27,5 @@ def day2(part=1):
if (pwd[start-1] == letter and pwd[end-1] != letter) or (pwd[start-1] != letter and pwd[end-1] == letter):
count += 1
return count
print(day2(part=1))
print(day2(part=2))
print('Part 1: '+day2(part=1))
print('Part 2: '+day2(part=2))
38 changes: 38 additions & 0 deletions 2020/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# If you already have the data as an input use:
from re import L


data = [] # Your Advent Input
# However, it is highly recommended to run this:
location = "C:\\Users\\dagam\\Downloads\\temp-files\\input.txt" # Path of the input.txt provided from Advent Calendar
try:
with open(location,'r') as f:
data = f.readlines()
f.close()
except:
pass
data = [o.rstrip('\n') for o in data]
if data[-1] == "'+":
del data[-1]

def tree_at_cord(x,y):
x_map = x % len(data[0]) # We need to repeat the tree data throughout the whole hill.
return data[y][x_map] == "#"
def increment(x_incr,y_incr):
x_cord, y_cord, trees = 0,0,0
while y_cord < len(data):
if tree_at_cord(x_cord,y_cord):
trees += 1
x_cord += x_incr
y_cord += y_incr
return trees
def day3(part=1):
if part not in [1,2]:
part = 1 # Default Part
if part == 1:
return increment(3,1)
else:
return increment(1,1)*increment(3,1)*increment(5,1)*increment(7,1)*increment(1,2)
print('Part 1: '+str(day3(part=1)))
print('Part 2: '+str(day3(part=2)))

0 comments on commit 767aa23

Please sign in to comment.