mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-06 19:14:19 -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')
|
||||
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))
|
||||
Reference in New Issue
Block a user