27 lines
615 B
Python
Executable File
27 lines
615 B
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
|
|
if __name__ == '__main__':
|
|
freq = 0
|
|
matches = {0: 1}
|
|
|
|
while True:
|
|
with open("input.txt") as fp:
|
|
line = fp.readline()
|
|
while line:
|
|
|
|
if line[:1] == "+":
|
|
freq += int(line[1:])
|
|
else:
|
|
freq -= int(line[1:])
|
|
|
|
if freq not in matches:
|
|
matches[freq] = 1
|
|
else:
|
|
print("Frequency reached twice: {}".format(freq))
|
|
sys.exit()
|
|
|
|
line = fp.readline()
|