34 lines
646 B
Python
34 lines
646 B
Python
import os
|
|
|
|
with open("../data/2015/1/input.txt", "r") as input_file:
|
|
floor = 0
|
|
while True:
|
|
char = input_file.read(1)
|
|
if not char:
|
|
break
|
|
|
|
if char == "(":
|
|
floor += 1
|
|
else:
|
|
floor -= 1
|
|
print("Part 1: {floor}".format(floor = floor))
|
|
|
|
input_file.seek(0)
|
|
floor = 0
|
|
steps = 0
|
|
while True:
|
|
char = input_file.read(1)
|
|
if not char:
|
|
break
|
|
|
|
steps += 1
|
|
if char == "(":
|
|
floor += 1
|
|
else:
|
|
floor -= 1
|
|
|
|
if floor < 0:
|
|
break
|
|
|
|
print("Part 2: {steps}".format(steps = steps))
|