commit 62dade14e138693105c1282e418e5a45c645a01b Author: PedroEdiaz Date: Wed Oct 29 17:19:47 2025 -0600 Add 1 -> 5 diff --git a/2015/1.py b/2015/1.py new file mode 100644 index 0000000..d5e8c98 --- /dev/null +++ b/2015/1.py @@ -0,0 +1,25 @@ +#!/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 diff --git a/2015/2.py b/2015/2.py new file mode 100644 index 0000000..373b59c --- /dev/null +++ b/2015/2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +# Fill Input +input = "" + +try: + with open("2.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; +for line in input.split('\n'): + if line == "": + break + + box = [int(n) for n in line.split('x')] + + box.sort() + l,w,h= box + + res1+=3*l*w+2*(w*h+l*h) + res2+=2*(l+w)+l*w*h + +print(res1, res2) diff --git a/2015/3.py b/2015/3.py new file mode 100644 index 0000000..a456300 --- /dev/null +++ b/2015/3.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# Fill Input +input = "" + +try: + with open("3.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 +coords = [[0,0],[0,0]] +houses = {key_coord([0,0]): santas} + +for c in input: + match c: + case '>': + coords[i][0]+=1 + case '<': + coords[i][0]-=1 + case '^': + coords[i][1]+=1 + case 'v': + coords[i][1]-=1 + + # A Dictonary for all the visisted houses + key=key_coord(coords[i]) + if key in houses: + houses[key]+=1; + else: + houses[key]=1; + + if santas > 1: + i^=1 + +print(len(houses)) diff --git a/2015/4.py b/2015/4.py new file mode 100644 index 0000000..415c3d7 --- /dev/null +++ b/2015/4.py @@ -0,0 +1,13 @@ +import hashlib + +zeros= 5 +input = "abcdef" + +for i in range(10**(zeros+1)): + string = input + str(i).zfill(zeros) + hash = hashlib.md5(string.encode('utf-8')).hexdigest() + + if hash.startswith(zeros*"0"): + print(i, hash) + break; + diff --git a/2015/5.py b/2015/5.py new file mode 100644 index 0000000..a1e4820 --- /dev/null +++ b/2015/5.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import re + +# Fill Input +input = "" + +try: + with open("5.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"): + res1 += int(match(r"(.)\1", line) and + match(r"(.*[aeiou]){3,}", line) and + not match(r"ab|cd|pq|xy", line) ) + + res2 += int(match(r"(..).*\1", line) and + match(r"(.).\1", line) ) + +print(res1, res2) +