diff --git a/2015/01.py b/2015/01.py new file mode 100644 index 0000000..617c37d --- /dev/null +++ b/2015/01.py @@ -0,0 +1,25 @@ +# Fill Input + +input = "" + +try: + with open("01.txt", 'r', encoding='utf-8') as file: + input += file.read() +except Exception as e: + print(f"An error occurred: {e}") + +# Result + +res1, res2 = 0, 0 + +for i in range(len(input)): + match input[i]: + case '(': + res1 += 1 + case ')': + res1 -= 1 + + if res1 < 0 and res2 == 0: + res2 = i+1 + +print(res1, res2) diff --git a/2015/2.py b/2015/02.py similarity index 76% rename from 2015/2.py rename to 2015/02.py index 373b59c..7d928b0 100644 --- a/2015/2.py +++ b/2015/02.py @@ -1,17 +1,16 @@ -#!/usr/bin/env python3 - # Fill Input + input = "" try: - with open("2.txt", 'r', encoding='utf-8') as file: + with open("02.txt", 'r', encoding='utf-8') as file: input += file.read() except Exception as e: print(f"An error occurred: {e}") # Result -res1 = 0; -res2 = 0; + +res1, res2 = 0, 0; for line in input.split('\n'): if line == "": break diff --git a/2015/3.py b/2015/03.py similarity index 89% rename from 2015/3.py rename to 2015/03.py index a456300..80a54dd 100644 --- a/2015/3.py +++ b/2015/03.py @@ -1,19 +1,20 @@ -#!/usr/bin/env python3 - # Fill Input + input = "" try: - with open("3.txt", 'r', encoding='utf-8') as file: + with open("03.txt", 'r', encoding='utf-8') as file: input += file.read() except Exception as e: print(f"An error occurred: {e}") # Convert Corrdenate to string + def key_coord(coord): return f"{coord[0]},{coord[1]}" # Result + santas = 1 # or 2 i=0 diff --git a/2015/4.py b/2015/04.py similarity index 100% rename from 2015/4.py rename to 2015/04.py diff --git a/2015/5.py b/2015/05.py similarity index 86% rename from 2015/5.py rename to 2015/05.py index a1e4820..7e39a02 100644 --- a/2015/5.py +++ b/2015/05.py @@ -1,21 +1,22 @@ -#!/usr/bin/env python3 - import re # Fill Input + input = "" try: - with open("5.txt", 'r', encoding='utf-8') as file: + with open("05.txt", 'r', encoding='utf-8') as file: input += file.read() except Exception as e: print(f"An error occurred: {e}") # regex matching + def match(pattern, string): return re.search(pattern, string) != None # Convert Corrdenate to string + res1, res2 = 0, 0 for line in input.split("\n"): diff --git a/2015/1.py b/2015/1.py deleted file mode 100644 index d5e8c98..0000000 --- a/2015/1.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 - -# Fill Input -input = "" - -try: - with open("1.txt", 'r', encoding='utf-8') as file: - input += file.read() -except Exception as e: - print(f"An error occurred: {e}") - -# Part 1 -print(input.count("(") - input.count(")")) - -# Part 2 -res = 0 -for i in range(len(input)): - match input[i]: - case '(': - res += 1 - case ')': - res -= 1 - if res < 0: - print(i+1) - break