-
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
0 parents
commit faff70f
Showing
15 changed files
with
286 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,12 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
total, res =0, [] | ||
for i in arr: | ||
if i == '': | ||
res.append(total) | ||
total = 0 | ||
else: | ||
total += int(i) | ||
print(max(res)) |
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,17 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
total, res = 0, [] | ||
for i in arr: | ||
if not i: | ||
res.append(total) | ||
total = 0 | ||
else: | ||
total += int(i) | ||
res.sort(reverse=True) | ||
final = 0 | ||
for i in range(3): | ||
final += res[i] | ||
|
||
print(final) |
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,21 @@ | ||
score = { | ||
'X':1, | ||
'Y':2, | ||
'Z':3 | ||
} | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
|
||
total = 0 | ||
for i in arr: | ||
k = score[i.split(' ')[1]] ## fetches the value of the last letter of the string | ||
i = i.replace(" ", "") # removes space | ||
if i == 'AX' or i == 'BY' or i == 'CZ': # draw | ||
total += 3 + k | ||
elif i == 'BX' or i == 'CY' or i == 'AZ': # loss | ||
total += 0 + k | ||
else: # win | ||
total += 6 + k | ||
print(total) |
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,32 @@ | ||
A = { | ||
'X':3, | ||
'Y':1, | ||
'Z':2 | ||
} | ||
B = { | ||
'X':1, | ||
'Y':2, | ||
'Z':3 | ||
} | ||
|
||
C = { | ||
'X':2, | ||
'Y':3, | ||
'Z':1 | ||
} | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
total = 0 | ||
for i in arr: | ||
i = i.replace(" ", "") | ||
j = i[0] | ||
k = i[1] | ||
if k == 'X': | ||
total += 0 + locals()[j][k] | ||
elif k == 'Z': | ||
total += 6 + locals()[j][k] | ||
else: | ||
total += 3 + locals()[j][k] | ||
print(total) |
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,19 @@ | ||
import string | ||
|
||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
|
||
low, high = list(zip(string.ascii_lowercase, range(1, 27))), list( | ||
zip(string.ascii_uppercase, range(27, 53))) | ||
chars = dict(low+high) | ||
|
||
total = 0 | ||
for i in arr: | ||
c1, c2 = i[:len(i)//2], i[len(i)//2:] | ||
for j in c1: | ||
if j in c2: | ||
total += chars[j] | ||
break | ||
print(total) |
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,26 @@ | ||
import string | ||
|
||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
|
||
low, high = list(zip(string.ascii_lowercase, range(1, 27))), list( | ||
zip(string.ascii_uppercase, range(27, 53))) | ||
chars = dict(low+high) | ||
|
||
def split(seq, size): | ||
return (seq[pos:pos + size] for pos in range(0, len(seq), size)) | ||
|
||
def check(arr): | ||
score = 0 | ||
for str in arr: | ||
for i in str: | ||
if i in arr[1] and i in arr[2]: | ||
score += chars[i] | ||
return score | ||
total = 0 | ||
for group in split(arr, 3): | ||
total += check(group) | ||
|
||
print(total) |
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,14 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
total = 0 | ||
for i in arr: | ||
ran = i.split(',') | ||
ran[0] = ran[0].split('-') | ||
ran[1] = ran[1].split('-') | ||
set1 = set(range(int(ran[0][0]), int(ran[0][1])+1)) | ||
set2 = set(range(int(ran[1][0]), int(ran[1][1])+1)) | ||
if set1.issubset(set2) or set2.issubset(set1): | ||
total += 1 | ||
print(total) |
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,15 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n') | ||
total = 0 | ||
for i in arr: | ||
ran = i.split(',') | ||
ran[0] = ran[0].split('-') | ||
ran[1] = ran[1].split('-') | ||
set1 = set(range(int(ran[0][0]), int(ran[0][1])+1)) | ||
set2 = set(range(int(ran[1][0]), int(ran[1][1])+1)) | ||
final = set1.intersection(set2) | ||
if len(final) != 0: | ||
total += 1 | ||
print(total) |
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,42 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n\n') | ||
ship, com = arr[0].split('\n'), arr[1].split('\n') | ||
|
||
cols = int(ship[-1][-1-1]) | ||
|
||
simp = dict({x: '' for x in range(1, cols+1)}) | ||
|
||
ship.pop(-1) | ||
for i in reversed(ship): | ||
i = i.split(' ') | ||
lum = 1 | ||
space = 0 | ||
for j in i: | ||
if space == 4: | ||
lum += 1 | ||
space = 0 | ||
if j == '': | ||
space += 1 | ||
continue | ||
j = j.replace('[', '').replace(']', '') | ||
if j.isalpha(): | ||
simp[lum] += j | ||
lum += 1 | ||
|
||
wl = set(' 1234567890') | ||
te = 10 | ||
for a in com: | ||
te += 1 | ||
a = ''.join(filter(wl.__contains__, a)) | ||
a = list(filter(None, a.split(' '))) | ||
a = [int(x) for x in a] | ||
for m in range(a[0]): | ||
simp[a[2]] = simp[a[2]] + simp[a[1]][-1] | ||
simp[a[1]] = simp[a[1]][:-1] | ||
|
||
for i in simp: | ||
print(simp[i][-1], end='') | ||
|
||
|
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,41 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
arr = output.split('\n\n') | ||
ship, com = arr[0].split('\n'), arr[1].split('\n') | ||
|
||
cols = int(ship[-1][-1-1]) | ||
|
||
simp = dict({x: '' for x in range(1, cols+1)}) | ||
|
||
ship.pop(-1) | ||
for i in reversed(ship): | ||
i = i.split(' ') | ||
lum = 1 | ||
space = 0 | ||
for j in i: | ||
if space == 4: | ||
lum += 1 | ||
space = 0 | ||
if j == '': | ||
space += 1 | ||
continue | ||
j = j.replace('[', '').replace(']', '') | ||
if j.isalpha(): | ||
simp[lum] += j | ||
lum += 1 | ||
|
||
wl = set(' 1234567890') | ||
te = 5 | ||
for a in com: | ||
te += 1 | ||
a = ''.join(filter(wl.__contains__, a)) | ||
a = list(filter(None, a.split(' '))) | ||
a = [int(x) for x in a] | ||
simp[a[2]] = simp[a[2]] + simp[a[1]][-a[0]:] | ||
|
||
simp[a[1]] = simp[a[1]][:-a[0]] | ||
|
||
|
||
for i in simp: | ||
print(simp[i][-1], end='') |
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,8 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
for i, s in enumerate(output): | ||
packet = output[i:i+4] | ||
if len(set(packet)) == len(packet): | ||
print(len(output[0:i+4])) | ||
break |
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,8 @@ | ||
with open('input.txt', 'r') as f: | ||
output = f.read() | ||
|
||
for i, s in enumerate(output): | ||
packet = output[i:i+14] | ||
if len(set(packet)) == len(packet): | ||
print(len(output[0:i+14])) | ||
break |
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,11 @@ | ||
with open('test.txt', 'r') as f: | ||
output = f.read() | ||
arr = output.split('\n') | ||
|
||
|
||
vis = len(arr[0]) + len(arr[-1]) | ||
|
||
for i, j in enumerate(arr[1:-1], 1): | ||
vis += 2 | ||
for j, k in enumerate(j[1:-1], 1): | ||
if k < |
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,20 @@ | ||
# ZeroQL's 2022 advent of code | ||
|
||
These are my solutions to the 2022 advent of code challenges. Written with love in python | ||
|
||
This is definitely not efficient code but i'm proud of myself regardless. | ||
|
||
## Terminology | ||
```AOC_[day]_[part].py``` | ||
- ``day`` indicates the challenge number | ||
- ``part`` indicates the associated part ``(1st or 2nd)`` | ||
|
||
for example ``AOC_5_P2.py`` would be my solution for the 2nd part of day 5 | ||
|
||
## Testing | ||
|
||
fork this repo or download the individual file and | ||
place your input in the ``input.txt`` file | ||
|
||
##### oh and star this rep too while your at it | ||
##### thanks :D |
Empty file.