-
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 4ec8072
Showing
37 changed files
with
1,230 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,3 @@ | ||
.venv/ | ||
.vscode/ | ||
2023 |
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 @@ | ||
col_one = []; | ||
col_two = []; | ||
|
||
with open('2024/01/input.txt') as f: | ||
for line in f: | ||
row = line.split(); | ||
col_one.append(int(row[0])); | ||
col_two.append(int(row[1])); | ||
|
||
col_one.sort(); | ||
col_two.sort(); | ||
|
||
sum = 0 | ||
|
||
for i, value in enumerate(col_one): | ||
sum += abs(value - col_two[i]); | ||
|
||
print(sum); | ||
|
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,33 @@ | ||
left_dict = {}; | ||
right_dict = {}; | ||
|
||
sum = 0; | ||
|
||
def getUniqueCountsOfKeys(list, dict): | ||
for key in list: | ||
if key in dict.keys(): | ||
dict[key] = dict[key] + 1; | ||
else: | ||
dict[key] = 1; | ||
|
||
def getSimilarityScores(list): | ||
for key in list: | ||
if key in right_dict.keys(): | ||
global sum; | ||
sum += int(key) * right_dict[key]; | ||
|
||
col_one = []; | ||
col_two = []; | ||
|
||
with open('2024/01/input.txt') as f: | ||
for line in f: | ||
row = line.split(); | ||
col_one.append(row[0]); | ||
col_two.append(row[1]); | ||
|
||
getUniqueCountsOfKeys(col_one, left_dict); | ||
getUniqueCountsOfKeys(col_two, right_dict); | ||
|
||
getSimilarityScores(col_one); | ||
|
||
print(sum); |
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,33 @@ | ||
lines = []; | ||
goodLines = 0; | ||
|
||
def testLine(line): | ||
numbers = line.split(' '); | ||
|
||
increasing = bool(int(numbers[0]) < int(numbers[1])) | ||
|
||
for i, number in enumerate(numbers): | ||
if i == 0: | ||
continue; | ||
|
||
diff = int(numbers[i]) - int(numbers[i - 1]); | ||
|
||
if increasing and diff < 0: | ||
return False; | ||
|
||
if not increasing and diff > 0: | ||
return False; | ||
|
||
if abs(diff) > 3 or diff == 0: | ||
return False; | ||
return True; | ||
|
||
|
||
with open('2024/02/input.txt') as f: | ||
for line in f: | ||
if testLine(line): | ||
goodLines = goodLines + 1; | ||
|
||
|
||
print(goodLines); | ||
|
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,44 @@ | ||
lines = []; | ||
goodLines = 0; | ||
|
||
def testTwoNumbers(increasing, first, second): | ||
diff = int(second) - int(first); | ||
if increasing and diff < 0: | ||
return False; | ||
|
||
if not increasing and diff > 0: | ||
return False; | ||
|
||
if abs(diff) > 3 or diff == 0: | ||
return False; | ||
return True; | ||
|
||
|
||
def testLine(numbers, savedOnce): | ||
increasing = bool(int(numbers[0]) < int(numbers[1])); | ||
|
||
for i, number in enumerate(numbers): | ||
if i == 0: | ||
continue; | ||
|
||
if not testTwoNumbers(increasing, numbers[i - 1], numbers[i]): | ||
if not savedOnce: | ||
for j, _ in enumerate(numbers): | ||
newArray = numbers[:]; | ||
newArray.pop(j); | ||
if testLine(newArray, True): | ||
return True; | ||
return False; | ||
else: | ||
return False; | ||
return True; | ||
|
||
|
||
with open('2024/02/input.txt') as f: | ||
for line in f: | ||
line = line.replace('\n','') | ||
numbers = line.split(' ') | ||
if testLine(numbers, False): | ||
goodLines = goodLines + 1; | ||
|
||
print(goodLines); |
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,18 @@ | ||
import re | ||
|
||
total = 0; | ||
|
||
def findMuls(line): | ||
pattern = re.findall(r"mul\([0-9]+,[0-9]+\)", line) | ||
return pattern | ||
|
||
|
||
with open('2024/03/input.txt') as f: | ||
for line in f: | ||
operations = findMuls(line); | ||
|
||
for operation in operations: | ||
mults = re.findall(r'\d+', operation); | ||
total += int(mults[0]) * int(mults[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,29 @@ | ||
import re | ||
|
||
total = 0; | ||
|
||
def findMuls(line): | ||
pattern = re.findall(r"mul\([0-9]+,[0-9]+\)", line) | ||
return pattern | ||
|
||
with open('2024/03/input.txt') as f: | ||
for line in f: | ||
operations = findMuls(line); | ||
instructions = re.findall(r"(mul\((\d{1,3}),(\d{1,3})\)|do\(\)|don\'t\(\))", line); | ||
|
||
enabled = True; | ||
|
||
for instruction in instructions: | ||
match instruction[0]: | ||
case 'do()': | ||
enabled = True; | ||
case 'don\'t()': | ||
enabled = False; | ||
case _: | ||
if enabled: | ||
mults = findMuls(instruction[0]) | ||
total += int(instruction[1]) * int(instruction[2]); | ||
|
||
|
||
|
||
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,50 @@ | ||
|
||
width = 0; | ||
height = 0; | ||
|
||
with open('2024/04/input.txt') as f: | ||
for line in f: | ||
width = len(line); | ||
height += 1; | ||
|
||
stringToFind = 'XMAS' | ||
|
||
def inBounds(number, length): | ||
if number < 0 or number >= length: | ||
return False; | ||
return True; | ||
|
||
# Recursively find the string | ||
def findIfContainsSubstring(fromX, fromY, xDir, yDir, substring): | ||
if len(substring) == 0: | ||
return True; | ||
|
||
global width, height; | ||
# ensure new spot isn't OoB | ||
newX = fromX + xDir; | ||
if not inBounds(newX, width): | ||
return False; | ||
newY = fromY + yDir; | ||
if not inBounds(newY, height): | ||
return False; | ||
|
||
if matrix[newX, newY] == substring[0]: | ||
return findIfContainsSubstring(newX, newY, xDir, yDir, substring[1:]); | ||
|
||
|
||
matrix = {} | ||
sequencesFound = 0; | ||
with open('2024/04/input.txt') as f: | ||
for i, line in enumerate(f): | ||
for j, char in enumerate(line.strip()): | ||
matrix[i,j] = char; | ||
|
||
for i in range(width): | ||
for j in range(height): | ||
if matrix[i,j] == stringToFind[0]: | ||
for xDir in range(-1,2): | ||
for yDir in range(-1,2): | ||
if findIfContainsSubstring(i,j, xDir, yDir, stringToFind[1:]): | ||
sequencesFound += 1; | ||
|
||
print(sequencesFound); |
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,64 @@ | ||
width = 0; | ||
height = 0; | ||
|
||
with open('2024/04/input.txt') as f: | ||
for line in f: | ||
width = len(line); | ||
height += 1; | ||
|
||
charsToFind = []; | ||
|
||
def resetCharsToFind(): | ||
global charsToFind; | ||
charsToFind = ['M', 'S']; | ||
|
||
def inBounds(number, length): | ||
if number < 0 or number >= length: | ||
return False; | ||
return True; | ||
|
||
def cornerIsGood(xPos, yPos): | ||
global charsToFind; | ||
global width, height; | ||
|
||
if not (inBounds(xPos, width) and inBounds(yPos, height)): | ||
return False; | ||
|
||
charAtPoint = matrix[xPos, yPos] | ||
if charAtPoint in charsToFind: | ||
return True; | ||
|
||
# Recursively find the string | ||
def charHasGoodDiagonal(xPos, yPos, xDir, yDir): | ||
global charsToFind; | ||
resetCharsToFind(); | ||
|
||
# ensure new spot isn't OoB | ||
cornerX = xPos + xDir; | ||
cornerY = yPos + yDir; | ||
|
||
if cornerIsGood(cornerX, cornerY): | ||
charsToFind.remove(matrix[cornerX, cornerY]); | ||
|
||
cornerX = xPos + (xDir * -1); | ||
cornerY = yPos + (yDir * -1); | ||
|
||
if cornerIsGood(cornerX, cornerY): | ||
return True; | ||
return False; | ||
|
||
|
||
matrix = {} | ||
crossesFound = 0; | ||
with open('2024/04/input.txt') as f: | ||
for i, line in enumerate(f): | ||
for j, char in enumerate(line.strip()): | ||
matrix[i,j] = char; | ||
|
||
for i in range(width): | ||
for j in range(height): | ||
if matrix[i,j] == 'A': | ||
if charHasGoodDiagonal(i, j, -1, -1) and charHasGoodDiagonal(i, j, 1, -1): | ||
crossesFound += 1; | ||
|
||
print(crossesFound); |
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,54 @@ | ||
instructions = []; | ||
|
||
allLines = []; | ||
goodLines = []; | ||
|
||
sum = 0; | ||
|
||
def testInput(num, numsBefore, numsAfter): | ||
for numBefore in numsBefore: | ||
if f"{num}|{numBefore}" in instructions: | ||
return False; | ||
|
||
for numAfter in numsAfter: | ||
if f"{numAfter}|{num}" in instructions: | ||
return False; | ||
|
||
return True; | ||
|
||
|
||
def testLine(line): | ||
numsBefore = [] | ||
numsAfter = [int(numeric_string) for numeric_string in line.split(',')]; | ||
|
||
while len(numsAfter) > 0: | ||
num = numsAfter.pop(0); | ||
if not testInput(num, numsBefore, numsAfter): | ||
return False; | ||
numsBefore.append(num); | ||
|
||
return True; | ||
|
||
with open('2024/05/input.txt') as f: | ||
for i, line in enumerate(f): | ||
line = line.strip(); | ||
if len(line) == 0: | ||
continue; | ||
|
||
if '|' not in line: | ||
# it's an input | ||
allLines.append(line); | ||
else: | ||
# it's an instruction | ||
instructions.append(line); | ||
|
||
for line in allLines: | ||
if testLine(line): | ||
goodLines.append(line) | ||
|
||
for line in goodLines: | ||
nums = [int(numeric_string) for numeric_string in line.split(',')]; | ||
index = int(len(nums) / 2); | ||
sum += nums[index]; | ||
|
||
print(sum) |
Oops, something went wrong.