From e7085453864431ace3ad8f3123b259ed0829ae74 Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Thu, 30 Dec 2021 15:11:21 -0800 Subject: all solutions for 2015 --- day1.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 day1.py (limited to 'day1.py') diff --git a/day1.py b/day1.py new file mode 100644 index 0000000..aa328b9 --- /dev/null +++ b/day1.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +with open('day1.txt') as data: + floors = data.read().strip() +# part 1 +print(sum(map(lambda x: 1 if x == '(' else -1, floors))) + +# part 2 +floor = 0 +for i, char in enumerate(floors): + if char == '(': + floor += 1 + else: + floor -= 1 + if floor == -1: + print(i+1) + break -- cgit 1.4.1-2-gfad0