Compare commits

...

3 commits

Author SHA1 Message Date
Dece 521cef0e58 2018 day 1 part 2 2019-12-22 01:41:19 +01:00
Dece 2386c6ad12 2018 day 1 part 1 2019-12-22 01:34:48 +01:00
Dece e497884c30 Make fetch script usable with different years 2019-12-22 01:31:50 +01:00
2 changed files with 24 additions and 3 deletions

19
2018/day1.py Normal file
View file

@ -0,0 +1,19 @@
import sys
changes = [int(line.rstrip()) for line in sys.stdin.readlines()]
# Part 1
print("Simple sum:", sum(changes))
# Part 2
freq = 0
history = {0: True}
found = False
while not found:
for c in changes:
freq += c
if freq in history:
found = True
break
history[freq] = True
print("First repeated:", freq)

View file

@ -1,16 +1,18 @@
from datetime import datetime
import os
import requests
import sys
if len(sys.argv) != 2:
if len(sys.argv) < 2:
print("Usage: <fetch> day")
sys.exit()
day = sys.argv[1]
year = sys.argv[2] if len(sys.argv) > 2 else str(datetime.now().year)
URL = "https://adventofcode.com/2019/day/{}/input"
URL = "https://adventofcode.com/{}/day/{}/input"
SESSION_ID = os.environ["AOC_SESSION"]
response = requests.get(URL.format(day), cookies={"session": SESSION_ID})
response = requests.get(URL.format(year, day), cookies={"session": SESSION_ID})
response.raise_for_status()
with open("day{}.txt".format(day), "wt") as output_file: