-
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
5894e8d
commit 2489051
Showing
5 changed files
with
137 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# If you already have the data as an input use: | ||
data = [] # Your Advent Calendar Input | ||
# However, it is highly recommended to run this: | ||
location = "" # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\') | ||
try: | ||
with open(location,'r') as f: | ||
data = f.readlines() | ||
f.close() | ||
except: | ||
pass | ||
data = [o.rstrip('\n') for o in data] | ||
def day1(part=1): | ||
res = [] | ||
count = 0 | ||
for i in data: | ||
if i == '': | ||
res.append(count) | ||
count = 0 | ||
else: count += int(i) | ||
|
||
if part == 1: return max(res) | ||
elif part == 2: | ||
total = 0 | ||
for _ in range(3): | ||
total += max(res) | ||
del res[res.index(max(res))] | ||
return total | ||
print('Part 1: '+str(day1(part=1))) | ||
print('Part 2: '+str(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# If you already have the data as an input use: | ||
data = [] # Your Advent Calendar Input | ||
# However, it is highly recommended to run this: | ||
location = "" # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\') | ||
try: | ||
with open(location,'r') as f: | ||
data = f.readlines() | ||
f.close() | ||
except: | ||
pass | ||
data = [o.rstrip('\n') for o in data] | ||
def day2(part=1): | ||
cond = { | ||
"A": {"X": 3, "Y": 6, "Z": 0}, | ||
"B": {"X": 0, "Y": 3, "Z": 6}, | ||
"C": {"X": 6, "Y": 0, "Z": 3}, | ||
} | ||
res = 0 | ||
for i in data: | ||
i = i.split(' ') | ||
if part == 1: | ||
res += list(cond["A"].keys()).index(i[1])+1 | ||
res += cond[i[0]][i[1]] | ||
elif part == 2: | ||
outcome = cond["B"][i[1]] | ||
res += [list(cond["A"].keys()).index(j)+1+outcome for j in cond[i[0]] if cond[i[0]][j] == outcome][0] | ||
return res | ||
print('Part 1: '+str(day2(part=1))) | ||
print('Part 2: '+str(day2(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# If you already have the data as an input use: | ||
data = [] # Your Advent Calendar Input | ||
# However, it is highly recommended to run this: | ||
location = "" # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\') | ||
try: | ||
with open(location,'r') as f: | ||
data = f.readlines() | ||
f.close() | ||
except: | ||
pass | ||
data = [o.rstrip('\n') for o in data] | ||
def day3(part=1): | ||
import string | ||
res = 0 | ||
if part == 1: | ||
for i in data: | ||
one, two = i[len(i)//2:], i[:len(i)//2] | ||
common = ''.join(set.intersection(set(one), set(two))) | ||
res += string.ascii_letters.index(common)+1 | ||
elif part == 2: | ||
grouped = zip(*(iter(data),)*3) | ||
for i in grouped: | ||
common = ''.join(set.intersection(set(i[0]), set(i[1]), set(i[2]))) | ||
res += string.ascii_letters.index(common)+1 | ||
return res | ||
print('Part 1: '+str(day3(part=1))) | ||
print('Part 2: '+str(day3(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# If you already have the data as an input use: | ||
data = [] # Your Advent Calendar Input | ||
# However, it is highly recommended to run this: | ||
location = " " # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\') | ||
try: | ||
with open(location,'r') as f: | ||
data = f.readlines() | ||
f.close() | ||
except: | ||
pass | ||
data = [o.rstrip('\n') for o in data] | ||
def day4(part=1): | ||
res = 0 | ||
for i in data: | ||
min1, max1, min2, max2 = *(int(x) for x in i.split(',')[0].split('-')), *(int(x) for x in i.split(',')[1].split('-')) | ||
if part == 1: | ||
if (min1 <= min2 and max1 >= max2) or (min1 >= min2 and max1 <= max2): | ||
res += 1 | ||
elif part == 2: | ||
if (min1 <= min2 <= max1) or (min2 <= min1 <= max2): | ||
res += 1 | ||
return res | ||
print('Part 1: '+str(day4(part=1))) | ||
print('Part 2: '+str(day4(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# If you already have the data as an input use: | ||
data = [] # Your Advent Calendar Input | ||
# However, it is highly recommended to run this: | ||
location = "" # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\') | ||
try: | ||
with open(location,'r') as f: | ||
data = f.readlines() | ||
f.close() | ||
except: | ||
pass | ||
data = [o.rstrip('\n') for o in data] | ||
def day5(part=1): | ||
import re | ||
moves = data[data.index('')+1:] | ||
_crates = [c.replace(' ',' ').split(' ') for c in data[:data.index('')-1]] | ||
_crates = [''.join([_crates[j][i] for j in range(len(_crates))]) for i in range(len(_crates[0]))] | ||
crates = [re.findall('([A-Z])+', crate)[::-1] for crate in _crates] | ||
for m in moves: | ||
a, b, c = map(int, re.findall(r'\d+', m)) | ||
if part == 1: | ||
for _ in range(a): | ||
crates[c-1].append(crates[b-1].pop()) | ||
elif part == 2: | ||
crates[c-1] = crates[c-1] + crates[b-1][-a:] | ||
crates[b-1] = crates[b-1][:-a] | ||
return ''.join(c[-1] for c in crates if len(c) > 0) | ||
print('Part 1: '+str(day5(part=1))) | ||
print('Part 2: '+str(day5(part=2))) |