Start solving 2018 problems

I have also updated get.py to download the problems as
`d<day>.txt` instead of `i<day>.txt`. That allows me
to get the day input via `__input__.replace('.py', '.txt')`
which is a little more concise. I don't know why
I didn't do this earlier.
This commit is contained in:
2024-07-04 11:10:11 -04:00
parent dcfae2cb13
commit 3a915cb9e3
7 changed files with 204 additions and 1 deletions

28
2018/d1.py Normal file
View File

@@ -0,0 +1,28 @@
def part_1(data):
r = 0
for x in data.splitlines():
r += int(x)
print(r)
def part_2(data):
seen = set()
r = 0
while True:
for x in data.splitlines():
r += int(x)
if r in seen:
print(r)
return
seen.add(r)
def main():
with open("i1.txt") as f:
data = f.read()
part_1(data)
part_2(data)
if __name__ == "__main__":
main()