mirror of
https://github.com/ershisan99/advent-of-code.git
synced 2025-12-16 20:49:24 +00:00
2015 day 1 part 2 refactor
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
abs_file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||||
|
input = open(file_path).read().strip()
|
||||||
input = open(abs_file_path).read().strip()
|
|
||||||
|
|
||||||
result = input.count("(") - input.count(")")
|
result = input.count("(") - input.count(")")
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
|
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||||
rel_path = "./input.txt"
|
input = open(file_path).read().strip()
|
||||||
abs_file_path = os.path.join(script_dir, rel_path)
|
|
||||||
|
|
||||||
input = open(abs_file_path).read()
|
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for i, char in enumerate(list(input), start=1):
|
for i, char in enumerate(list(input), start=1):
|
||||||
|
if count == 0 and char == ")":
|
||||||
|
print(i)
|
||||||
|
break
|
||||||
if char == "(":
|
if char == "(":
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
else:
|
||||||
if count == 0:
|
|
||||||
print(i)
|
|
||||||
break
|
|
||||||
count -= 1
|
count -= 1
|
||||||
|
|||||||
Reference in New Issue
Block a user