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
|
# Fill Input
|
||||||
|
|
||||||
input = ""
|
input = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("2.txt", 'r', encoding='utf-8') as file:
|
with open("02.txt", 'r', encoding='utf-8') as file:
|
||||||
input += file.read()
|
input += file.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
# Result
|
# Result
|
||||||
res1 = 0;
|
|
||||||
res2 = 0;
|
res1, res2 = 0, 0;
|
||||||
for line in input.split('\n'):
|
for line in input.split('\n'):
|
||||||
if line == "":
|
if line == "":
|
||||||
break
|
break
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Fill Input
|
# Fill Input
|
||||||
|
|
||||||
input = ""
|
input = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("3.txt", 'r', encoding='utf-8') as file:
|
with open("03.txt", 'r', encoding='utf-8') as file:
|
||||||
input += file.read()
|
input += file.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
# Convert Corrdenate to string
|
# Convert Corrdenate to string
|
||||||
|
|
||||||
def key_coord(coord):
|
def key_coord(coord):
|
||||||
return f"{coord[0]},{coord[1]}"
|
return f"{coord[0]},{coord[1]}"
|
||||||
|
|
||||||
# Result
|
# Result
|
||||||
|
|
||||||
santas = 1 # or 2
|
santas = 1 # or 2
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
@@ -1,21 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Fill Input
|
# Fill Input
|
||||||
|
|
||||||
input = ""
|
input = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("5.txt", 'r', encoding='utf-8') as file:
|
with open("05.txt", 'r', encoding='utf-8') as file:
|
||||||
input += file.read()
|
input += file.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
# regex matching
|
# regex matching
|
||||||
|
|
||||||
def match(pattern, string):
|
def match(pattern, string):
|
||||||
return re.search(pattern, string) != None
|
return re.search(pattern, string) != None
|
||||||
|
|
||||||
# Convert Corrdenate to string
|
# Convert Corrdenate to string
|
||||||
|
|
||||||
res1, res2 = 0, 0
|
res1, res2 = 0, 0
|
||||||
|
|
||||||
for line in input.split("\n"):
|
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