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:
28
2018/d1.py
Normal file
28
2018/d1.py
Normal 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()
|
||||
Reference in New Issue
Block a user