Skip to content

Instantly share code, notes, and snippets.

@wakemaster39
Created December 1, 2018 21:46
Show Gist options
  • Save wakemaster39/e3bf23439154383a744d248946efb7cf to your computer and use it in GitHub Desktop.
Save wakemaster39/e3bf23439154383a744d248946efb7cf to your computer and use it in GitHub Desktop.
import requests
import os
dir = os.path.dirname(__file__)
f = open(os.path.join(dir, "data.txt"))
inputs = [int(x) for x in f]
# Question 1 answer
print(sum(inputs))
seen = set()
current = 0
count = 0
while True:
for x in inputs:
current += x
if current in seen:
# Question 2 answer
print(current)
break
seen.add(current)
else:
print(count)
count += 1
continue
break
@harryvgiunta
Copy link

harryvgiunta commented Dec 2, 2018

My solution:

import pandas as p

file = p.read_excel('C:/AdventOfCode/DayOne.xlsx')
data = []

for num in file['numbers']:
    data.append(num)
print("part one answer:", sum(data))

cf = 0
previousfrequencies = [0]
duplicatefound = False

while duplicatefound is False:
    for num in data:
        cf = num + cf
        if cf in previousfrequencies:
            print("part two answer:", cf)
            duplicatefound = True
            break
        previousfrequencies.append(cf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment