This commit is contained in:
Joscha 2018-12-02 22:20:44 +00:00
commit f2f6c048fb
3 changed files with 1005 additions and 0 deletions

35
01/solve.py Normal file
View file

@ -0,0 +1,35 @@
import sys
def load_freqs(filename):
freqs = []
with open(filename, "r") as f:
for line in f:
n = int(line[1:-1])
if line[0] == "-":
n = -n
freqs.append(n)
return freqs
def find_repeat(freqs):
total = 0
found = {total}
while True:
for n in freqs:
total += n
if total in found:
return total
else:
found.add(total)
def main(filename):
freqs = load_freqs(filename)
print(" Part 1")
print(f"Total: {sum(freqs)}")
print()
print(" Part 2")
print(f"First repeat: {find_repeat(freqs)}")
if __name__ == "__main__":
for filename in sys.argv[1:]:
main(filename)