[Python/2017] Move solutions into .py files
This commit is contained in:
parent
fbc5fda60f
commit
7b1efc0d9c
51 changed files with 1100 additions and 4546 deletions
54
Python/2017/09.py
Normal file
54
Python/2017/09.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2017, 9)
|
||||
|
||||
|
||||
out = 0
|
||||
level = 0
|
||||
garbage = False
|
||||
skip = False
|
||||
for c in input:
|
||||
if skip:
|
||||
skip = False
|
||||
continue
|
||||
if garbage:
|
||||
if c == "!":
|
||||
skip = True
|
||||
elif c == ">":
|
||||
garbage = False
|
||||
else:
|
||||
if c == "{":
|
||||
level += 1
|
||||
elif c == "}":
|
||||
out += level
|
||||
level -= 1
|
||||
elif c == "<":
|
||||
garbage = True
|
||||
|
||||
print(out)
|
||||
|
||||
|
||||
out = 0
|
||||
level = 0
|
||||
garbage = False
|
||||
skip = False
|
||||
for c in input:
|
||||
if skip:
|
||||
skip = False
|
||||
continue
|
||||
if garbage:
|
||||
if c == "!":
|
||||
skip = True
|
||||
elif c == ">":
|
||||
garbage = False
|
||||
else:
|
||||
out += 1
|
||||
else:
|
||||
if c == "{":
|
||||
level += 1
|
||||
elif c == "}":
|
||||
level -= 1
|
||||
elif c == "<":
|
||||
garbage = True
|
||||
|
||||
print(out)
|
Loading…
Add table
Add a link
Reference in a new issue