day 1 and day 2 edits, day 1 part 2

This commit is contained in:
Xevion
2019-07-26 14:10:27 -06:00
parent 86920028d4
commit 17b61b6cd7
2 changed files with 36 additions and 8 deletions

View File

@@ -1,9 +1,26 @@
import os, sys, pyperclip
import os, sys, pyperclip, itertools, time
t1 = time.time()
path = os.path.join(sys.path[0], '..', 'input')
data = open(path, 'r').read()
data = map(int, data.split('\n'))
data = sum(data)
data = list(map(int, data.split('\n')))
# data = [+7, +7, -2, -7, -4]
datacycle = itertools.cycle(data)
final = sum(data) # day 1 solution
print(data)
pyperclip.copy(data)
curfreq = 0
i = 0
prevfreq = set()
searching = True
while searching:
i += 1
curfreq += next(datacycle)
if curfreq in prevfreq:
searching = False
break
prevfreq.add(curfreq)
t2 = time.time()
print("Calculation completed in {}ms".format( round((t2 - t1) * 1000, 2) ))
print("Final Frequency: {}".format(final))
print("Frequency {} repeated after {} iterations.".format(curfreq, i))

View File

@@ -5,9 +5,20 @@ def count(string):
path = os.path.join(sys.path[0], '..', 'input')
data = open(path, 'r').read().split('\n')
data = sum(map(count, data), [])
two, three = data.count(2), data.count(3)
sums = sum(map(count, data), [])
two, three = sums.count(2), sums.count(3)
answer = two * three
print("{} x {} = {}".format(two, three, answer))
pyperclip.copy(answer)
pyperclip.copy(answer)
try:
for id1 in data:
for id2 in data:
diff = [i for i in range(len(id1)) if id1[i] != id2[i]]
if len(diff) == 1:
e = [id1[i] for i in range(len(id1)) if i not in diff]
print(''.join(e))
raise Exception()
except:
pass