[py] Port 2018_01
This commit is contained in:
parent
0272942104
commit
31d6098c58
4 changed files with 19 additions and 38 deletions
|
|
@ -1,33 +0,0 @@
|
|||
import sys
|
||||
|
||||
def load_freqs(filename):
|
||||
freqs = []
|
||||
with open(filename, "r") as f:
|
||||
for line in f:
|
||||
n = int(line[:-1])
|
||||
freqs.append(n)
|
||||
return freqs
|
||||
|
||||
# PART 2
|
||||
|
||||
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(f"Solutions for {filename}")
|
||||
print(f"Part 1: {sum(freqs)}")
|
||||
print(f"Part 2: {find_repeat(freqs)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
for filename in sys.argv[1:]:
|
||||
main(filename)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
+1
|
||||
+2
|
||||
-3
|
||||
-4
|
||||
+5
|
||||
Loading…
Add table
Add a link
Reference in a new issue