Implemented Day 01 of 2015 with Python

This commit is contained in:
2025-06-06 00:10:28 +02:00
parent 7a88149ed9
commit 536070e45c
4 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1 @@
3.13

34
2015/01/python/main.py Normal file
View 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()

View 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
View File

@@ -0,0 +1,8 @@
version = 1
revision = 2
requires-python = ">=3.13"
[[package]]
name = "python"
version = "0.1.0"
source = { virtual = "." }