From 9366d2dae69ff22ba96334f2db4349d2f26b233f Mon Sep 17 00:00:00 2001 From: Mart <52244208+phiMale@users.noreply.github.com> Date: Mon, 23 Oct 2023 10:44:22 +0000 Subject: [PATCH 1/9] first commit for local clone --- day01/day01.py | 12 +++++++++--- day02/day02.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/day01/day01.py b/day01/day01.py index 9f69ffd..a521d28 100644 --- a/day01/day01.py +++ b/day01/day01.py @@ -20,9 +20,15 @@ def __init__(self): self.currentFrequency = 0 def calibrate(self, num: int): - pass + self.currentFrequency += num # put your inputs file next to this file! -lines = read_input('input.txt'); -# solve the problem here! \ No newline at end of file +lines = read_input('input.txt') +# solve the problem here! +f = Frequency() + +for freq in lines: + f.calibrate(freq) + +print(f.currentFrequency) \ No newline at end of file diff --git a/day02/day02.py b/day02/day02.py index 7ea619d..e664283 100644 --- a/day02/day02.py +++ b/day02/day02.py @@ -14,4 +14,16 @@ def read_input(file_name): #a lines = read_input('input.txt') -# solve the problem here! \ No newline at end of file +# solve the problem here! +class Frequency: + def __init__(self): + self.currentFrequency = 0 + + def calibrate(self, num: int): + self.currentFrequency += num + + +f = Frequency() + +for freq in lines: + f.calibrate(freq) \ No newline at end of file From 87dfa0254aef01dfcd3d016a263a45f31bf6689b Mon Sep 17 00:00:00 2001 From: KMT Date: Sat, 28 Oct 2023 15:57:09 +0200 Subject: [PATCH 2/9] no idea why this didn't work, hope it does now --- day01/day01.py | 14 +++++++++++--- day02/day02.py | 14 +------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/day01/day01.py b/day01/day01.py index a521d28..a6d8d24 100644 --- a/day01/day01.py +++ b/day01/day01.py @@ -17,11 +17,18 @@ def read_input(file_name): class Frequency: def __init__(self): + self.input_file = "input.txt" self.currentFrequency = 0 + self.lines = read_input(self.input_file) - def calibrate(self, num: int): + def calibrate(self, num: int): self.currentFrequency += num + def compare(self): + buf = int[len(self.lines)] + + + # put your inputs file next to this file! lines = read_input('input.txt') @@ -29,6 +36,7 @@ def calibrate(self, num: int): f = Frequency() for freq in lines: - f.calibrate(freq) + f.calibrate(freq) + +print(f.currentFrequency) -print(f.currentFrequency) \ No newline at end of file diff --git a/day02/day02.py b/day02/day02.py index e664283..7ea619d 100644 --- a/day02/day02.py +++ b/day02/day02.py @@ -14,16 +14,4 @@ def read_input(file_name): #a lines = read_input('input.txt') -# solve the problem here! -class Frequency: - def __init__(self): - self.currentFrequency = 0 - - def calibrate(self, num: int): - self.currentFrequency += num - - -f = Frequency() - -for freq in lines: - f.calibrate(freq) \ No newline at end of file +# solve the problem here! \ No newline at end of file From 64e8ae41f66ec6adbb84aa3e428f6cdb2ffba6a8 Mon Sep 17 00:00:00 2001 From: KMT Date: Sat, 28 Oct 2023 21:09:48 +0200 Subject: [PATCH 3/9] day01 version 1 --- day01/day01.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/day01/day01.py b/day01/day01.py index a6d8d24..910554e 100644 --- a/day01/day01.py +++ b/day01/day01.py @@ -2,6 +2,7 @@ from typing import List; import os; import time; +import numpy as np def read_input(file_name): current_path = os.path.dirname(__file__) @@ -17,26 +18,33 @@ def read_input(file_name): class Frequency: def __init__(self): - self.input_file = "input.txt" - self.currentFrequency = 0 - self.lines = read_input(self.input_file) + self.current_frequency = 0 + self.first_rep = None - def calibrate(self, num: int): - self.currentFrequency += num + def calibration(self, num: int): + self.current_frequency += num - def compare(self): - buf = int[len(self.lines)] + def detect_first_rep(self, inputs): + freq_dict = {} + self.current_frequency = 0 + 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 - - -# put your inputs file next to this file! -lines = read_input('input.txt') -# solve the problem here! f = Frequency() +inputs = read_input('input.txt') + +for freq in inputs: + f.calibration(freq) -for freq in lines: - f.calibrate(freq) +print("The sum of all frequencies is ", f.current_frequency) -print(f.currentFrequency) +f.detect_first_rep(inputs) +print("The first repeating frequency is ", f.first_rep) \ No newline at end of file From db7617a54293266a43da75adf606690147301970 Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 00:14:28 +0200 Subject: [PATCH 4/9] added day01 v2, doesn't work yet. --- day01/day01.py | 2 +- day01/day01_v2.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 day01/day01_v2.py diff --git a/day01/day01.py b/day01/day01.py index 910554e..4e4c651 100644 --- a/day01/day01.py +++ b/day01/day01.py @@ -2,7 +2,6 @@ from typing import List; import os; import time; -import numpy as np def read_input(file_name): current_path = os.path.dirname(__file__) @@ -27,6 +26,7 @@ def calibration(self, num: int): def detect_first_rep(self, inputs): freq_dict = {} self.current_frequency = 0 + while (1): for freq in inputs: self.calibration(freq) diff --git a/day01/day01_v2.py b/day01/day01_v2.py new file mode 100644 index 0000000..3dd2af1 --- /dev/null +++ b/day01/day01_v2.py @@ -0,0 +1,37 @@ + +from typing import List; +import os; +import time; +import numpy as np + +def read_input(file_name): + current_path = os.path.dirname(__file__) + lines : List[int] = [] + try: + with open(os.path.join(current_path, file_name), 'r') as file: + for line in file: + lines.append(int(line.strip())) + except Exception as e: + print(f"An error occurred: {e}") + return lines + +def freq_calculations(inputs): + cumlsum_inputs = np.cumsum(inputs) + print("The sum of all frequencies is ", cumlsum_inputs[-1]) + cumlsum_dict = {} + while True: + + i = 0 + for line in cumlsum_inputs: + i += 1 + if line in cumlsum_dict: + print("The first repeating frequency is ", line) + print(cumlsum_inputs[i]) + return + else: + cumlsum_dict[line] = None + cumlsum_inputs += cumlsum_inputs[-1] + + +inputs = read_input('input.txt') +freq_calculations(inputs) \ No newline at end of file From 3db85db76e37928201c910d0def5bb29ce9eb019 Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 11:57:50 +0100 Subject: [PATCH 5/9] last attempt at day01_v2.py --- day01/day01_v2.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/day01/day01_v2.py b/day01/day01_v2.py index 3dd2af1..8b27012 100644 --- a/day01/day01_v2.py +++ b/day01/day01_v2.py @@ -15,22 +15,41 @@ def read_input(file_name): print(f"An error occurred: {e}") return lines +def calibration(inputs): + sums = np.zeros(len(inputs)) + i = 0 + a = 0 + csums = np.cumsum(inputs) + for line in inputs: + a += line + sums[i] = a + if (a != csums[i]): + print("ERROR") + i += 1 + + return sums + + + def freq_calculations(inputs): - cumlsum_inputs = np.cumsum(inputs) + cumlsum_inputs = calibration(inputs)# np.cumsum(inputs) print("The sum of all frequencies is ", cumlsum_inputs[-1]) cumlsum_dict = {} + i = 0 while True: - i = 0 + for line in cumlsum_inputs: - i += 1 + if line in cumlsum_dict: print("The first repeating frequency is ", line) - print(cumlsum_inputs[i]) + print(cumlsum_dict[line]) return else: - cumlsum_dict[line] = None + cumlsum_dict[line] = i + i += 1 cumlsum_inputs += cumlsum_inputs[-1] + inputs = read_input('input.txt') From be0c26fa1d8ccc97611a866f4b734320f61741bf Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 11:58:44 +0100 Subject: [PATCH 6/9] screw it. day01.py will have to do --- day01/day01_v2.py | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 day01/day01_v2.py diff --git a/day01/day01_v2.py b/day01/day01_v2.py deleted file mode 100644 index 8b27012..0000000 --- a/day01/day01_v2.py +++ /dev/null @@ -1,56 +0,0 @@ - -from typing import List; -import os; -import time; -import numpy as np - -def read_input(file_name): - current_path = os.path.dirname(__file__) - lines : List[int] = [] - try: - with open(os.path.join(current_path, file_name), 'r') as file: - for line in file: - lines.append(int(line.strip())) - except Exception as e: - print(f"An error occurred: {e}") - return lines - -def calibration(inputs): - sums = np.zeros(len(inputs)) - i = 0 - a = 0 - csums = np.cumsum(inputs) - for line in inputs: - a += line - sums[i] = a - if (a != csums[i]): - print("ERROR") - i += 1 - - return sums - - - -def freq_calculations(inputs): - cumlsum_inputs = calibration(inputs)# np.cumsum(inputs) - print("The sum of all frequencies is ", cumlsum_inputs[-1]) - cumlsum_dict = {} - i = 0 - while True: - - - for line in cumlsum_inputs: - - if line in cumlsum_dict: - print("The first repeating frequency is ", line) - print(cumlsum_dict[line]) - return - else: - cumlsum_dict[line] = i - i += 1 - cumlsum_inputs += cumlsum_inputs[-1] - - - -inputs = read_input('input.txt') -freq_calculations(inputs) \ No newline at end of file From f24c1d49bdb1b954112b5abb5e7de20dfa890fde Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 12:39:37 +0100 Subject: [PATCH 7/9] added day02.py --- day02/day02.py | 22 ++++++++++++++++++++-- day02/testinput.txt | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 day02/testinput.txt 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 diff --git a/day02/testinput.txt b/day02/testinput.txt new file mode 100644 index 0000000..6f286e3 --- /dev/null +++ b/day02/testinput.txt @@ -0,0 +1,3 @@ +abbab +cdcdcd +abcd \ No newline at end of file From 3460db49b32da4ced1a8318ca651b3aba0cb2818 Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 12:39:37 +0100 Subject: [PATCH 8/9] added day02.py --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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__/ From c5f3e8700c8cbb5a6fab2f274e318f3f2f879aaa Mon Sep 17 00:00:00 2001 From: KMT Date: Sun, 29 Oct 2023 12:45:49 +0100 Subject: [PATCH 9/9] deleted testinput.txt --- day02/testinput.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 day02/testinput.txt diff --git a/day02/testinput.txt b/day02/testinput.txt deleted file mode 100644 index 6f286e3..0000000 --- a/day02/testinput.txt +++ /dev/null @@ -1,3 +0,0 @@ -abbab -cdcdcd -abcd \ No newline at end of file