2015/day01: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
4489f9da18
commit
3a240d8a9a
|
@ -0,0 +1 @@
|
||||||
|
# Advent of Code, 2015 (in 2023, for fun)
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from typing import TextIO
|
||||||
|
|
||||||
|
|
||||||
|
f = open("day01.txt", "r")
|
||||||
|
floors = f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
|
def part1() -> int:
|
||||||
|
return 0 + floors.count("(") - floors.count(")")
|
||||||
|
|
||||||
|
|
||||||
|
def part2() -> int:
|
||||||
|
position = 1
|
||||||
|
current = 0
|
||||||
|
|
||||||
|
for a in floors:
|
||||||
|
if a == "(":
|
||||||
|
current += 1
|
||||||
|
else:
|
||||||
|
current -= 1
|
||||||
|
|
||||||
|
if current == -1:
|
||||||
|
return position
|
||||||
|
|
||||||
|
position += 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(part1())
|
||||||
|
print(part2())
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue