Implemented Day 01 of 2015 with Python
This commit is contained in:
1
2015/01/python/.python-version
Normal file
1
2015/01/python/.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.13
|
||||||
34
2015/01/python/main.py
Normal file
34
2015/01/python/main.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
def main():
|
||||||
|
input = read_file("../input.txt")
|
||||||
|
data = list(input)
|
||||||
|
print(part1(data))
|
||||||
|
print(part2(data))
|
||||||
|
|
||||||
|
def part1(data: list[str]) -> int:
|
||||||
|
floor_level = 0
|
||||||
|
for c in data:
|
||||||
|
if c == "(":
|
||||||
|
floor_level += 1
|
||||||
|
else:
|
||||||
|
floor_level -= 1
|
||||||
|
return floor_level
|
||||||
|
|
||||||
|
def part2(data: list[str]) -> int:
|
||||||
|
floor_level = 0
|
||||||
|
location_index = 0
|
||||||
|
for i, c in enumerate(data):
|
||||||
|
if c == "(":
|
||||||
|
floor_level += 1
|
||||||
|
else:
|
||||||
|
floor_level -= 1
|
||||||
|
if floor_level == -1:
|
||||||
|
location_index = i
|
||||||
|
break
|
||||||
|
return location_index + 1
|
||||||
|
|
||||||
|
def read_file(filename: str) -> str:
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
7
2015/01/python/pyproject.toml
Normal file
7
2015/01/python/pyproject.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[project]
|
||||||
|
name = "python"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
dependencies = []
|
||||||
8
2015/01/python/uv.lock
generated
Normal file
8
2015/01/python/uv.lock
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version = 1
|
||||||
|
revision = 2
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = { virtual = "." }
|
||||||
Reference in New Issue
Block a user