-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63c5820
commit 767aa23
Showing
3 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|