[py] Port 2018_01
This commit is contained in:
parent
0272942104
commit
31d6098c58
4 changed files with 19 additions and 38 deletions
17
py/aoc/y2018/d01.py
Normal file
17
py/aoc/y2018/d01.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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 solve(inputstr):
|
||||
freqs = [int(freq) for freq in inputstr.splitlines()]
|
||||
print(f"Part 1: {sum(freqs)}")
|
||||
print(f"Part 2: {find_repeat(freqs)}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue