Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions day01/day01.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

from typing import List;
import os;
import time;

def read_input(file_name):
current_path = os.path.dirname(__file__)
Expand All @@ -19,10 +17,33 @@ class Frequency:
def __init__(self):
self.currentFrequency = 0

def calibrate(self, num: int):
pass
def calibrate(self, num: int):
self.currentFrequency += num


# put your inputs file next to this file!
lines = read_input('input.txt');
# solve the problem here!
lines = read_input('input.txt')

# Part 1
f = Frequency()
for freq in lines:
f.calibrate(freq)

print("Part 1:", f.currentFrequency)

# Part 2
f_ = Frequency()
foundDuplicate = False
freqSet = set()

while foundDuplicate == False:
for freq in lines:
f_.calibrate(freq)

if f_.currentFrequency in freqSet:
foundDuplicate = True
break

freqSet.add(f_.currentFrequency)

print("Part 2:", f_.currentFrequency)
57 changes: 55 additions & 2 deletions day02/day02.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,59 @@ def read_input(file_name):
print(f"An error occurred: {e}")
return lines

#a

lines = read_input('input.txt')
# solve the problem here!
# solve the problem here
# Part 1
def count_letter_occurrences():
count_doubles = 0
count_tripples = 0
# Iterate through the input list
for line in lines:
letter_counts = {}

for letter in line:
if letter in letter_counts:
letter_counts[letter] += 1
else:
letter_counts[letter] = 1

# Check if any letter appears exactly two or three times
if 2 in letter_counts.values():
count_doubles += 1
if 3 in letter_counts.values():
count_tripples += 1

return count_doubles, count_tripples

def calc_checksum(num1, num2):
return num1 * num2

double,tripple = count_letter_occurrences()

# Calculate the checksum by multiplying the counts
checksum = calc_checksum(double, tripple)
print(checksum)

# Part 2
# Function to find the common letters between two box IDs
def find_common_letters(line, line_):
common_letter = []
for letter, letter_ in zip(line, line_):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very elegant using zip here! 👍

if letter == letter_:
common_letter.append(letter)

if len(common_letter) == len(lines[0]) - 1:
for letters in common_letter:
print(letters, end="")
return

# Iterate through the list to find the correct pair
i = 0
common_letters = []
while i < len(lines):
j = i + 1
while j < len(lines):
find_common_letters(lines[i], lines[j])
j += 1
i += 1