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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
input.txt
testinput.txt

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
34 changes: 28 additions & 6 deletions day01/day01.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,34 @@ def read_input(file_name):

class Frequency:
def __init__(self):
self.currentFrequency = 0
self.current_frequency = 0
self.first_rep = None

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

def detect_first_rep(self, inputs):
freq_dict = {}
self.current_frequency = 0

# put your inputs file next to this file!
lines = read_input('input.txt');
# solve the problem here!
while (1):
for freq in inputs:
self.calibration(freq)
if self.current_frequency in freq_dict:
self.first_rep = self.current_frequency
return
else:
freq_dict[self.current_frequency] = None


f = Frequency()
inputs = read_input('input.txt')

for freq in inputs:
f.calibration(freq)

print("The sum of all frequencies is ", f.current_frequency)

f.detect_first_rep(inputs)

print("The first repeating frequency is ", f.first_rep)
22 changes: 20 additions & 2 deletions day02/day02.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ def read_input(file_name):
print(f"An error occurred: {e}")
return lines

#a

lines = read_input('input.txt')
# solve the problem here!
cnt_two = 0
cnt_three = 0

flag_two = False
flag_three = False

for idn in lines:
char_dict = {}
for char in idn:
if char in char_dict:
char_dict[char] += 1
else:
char_dict[char] = 1
if 2 in char_dict.values():
cnt_two += 1
if 3 in char_dict.values():
cnt_three += 1

print("checksum: ", cnt_two * cnt_three)