mirror of
https://github.com/Xevion/advent-of-code.git
synced 2026-01-31 08:23:25 -06:00
day 1 and day 2 edits, day 1 part 2
This commit is contained in:
@@ -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')
|
path = os.path.join(sys.path[0], '..', 'input')
|
||||||
data = open(path, 'r').read()
|
data = open(path, 'r').read()
|
||||||
data = map(int, data.split('\n'))
|
data = list(map(int, data.split('\n')))
|
||||||
data = sum(data)
|
# data = [+7, +7, -2, -7, -4]
|
||||||
|
datacycle = itertools.cycle(data)
|
||||||
|
final = sum(data) # day 1 solution
|
||||||
|
|
||||||
print(data)
|
curfreq = 0
|
||||||
pyperclip.copy(data)
|
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))
|
||||||
@@ -5,9 +5,20 @@ def count(string):
|
|||||||
|
|
||||||
path = os.path.join(sys.path[0], '..', 'input')
|
path = os.path.join(sys.path[0], '..', 'input')
|
||||||
data = open(path, 'r').read().split('\n')
|
data = open(path, 'r').read().split('\n')
|
||||||
data = sum(map(count, data), [])
|
sums = sum(map(count, data), [])
|
||||||
two, three = data.count(2), data.count(3)
|
two, three = sums.count(2), sums.count(3)
|
||||||
|
|
||||||
answer = two * three
|
answer = two * three
|
||||||
print("{} x {} = {}".format(two, three, answer))
|
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
|
||||||
Reference in New Issue
Block a user