Skip to content

Instantly share code, notes, and snippets.

@Dutcho
Created December 2, 2018 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dutcho/6063f2f614feb95bc0a9a19c7f96dee3 to your computer and use it in GitHub Desktop.
Save Dutcho/6063f2f614feb95bc0a9a19c7f96dee3 to your computer and use it in GitHub Desktop.
AoC01.py
'''AoC 2018 #01, https://adventofcode.com/2018/day/1 - Olaf, 1 Dec 2018'''
with open('AoC01.txt') as file:
deltas = tuple(map(int, file.readlines()))
print('first answer', sum(deltas))
frequency, previous, found = 0, set(), False
while not found:
for freq in deltas:
previous |= {frequency}
frequency += freq
if frequency in previous:
print('second answer', frequency)
found = True
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment