rename n.py -> 0n.py
This commit is contained in:
25
2015/01.py
Normal file
25
2015/01.py
Normal file
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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"):
|
||||
25
2015/1.py
25
2015/1.py
@@ -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
|
||||
Reference in New Issue
Block a user