diff --git a/.gitignore b/.gitignore index 47e34cf..e6c9508 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ input.txt +testinput.txt # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/day01/day01.py b/day01/day01.py index 9f69ffd..4e4c651 100644 --- a/day01/day01.py +++ b/day01/day01.py @@ -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! \ No newline at end of file + 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) \ No newline at end of file diff --git a/day02/day02.py b/day02/day02.py index 7ea619d..80d8fa4 100644 --- a/day02/day02.py +++ b/day02/day02.py @@ -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! \ No newline at end of file +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) \ No newline at end of file