Add 1 -> 5
This commit is contained in:
25
2015/1.py
Normal file
25
2015/1.py
Normal file
@@ -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
|
||||||
27
2015/2.py
Normal file
27
2015/2.py
Normal file
@@ -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)
|
||||||
44
2015/3.py
Normal file
44
2015/3.py
Normal file
@@ -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))
|
||||||
13
2015/4.py
Normal file
13
2015/4.py
Normal file
@@ -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;
|
||||||
|
|
||||||
30
2015/5.py
Normal file
30
2015/5.py
Normal file
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user