Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
advent of code day 1
import datetime
input = "+15 -7 +16 +5 +12 +16 -4 +10 -1 +14 -16 +6 +4 +11 -2 +5 +4 +12 +13 +5 +16 +18 -3 -2 +9 -10 +12 -10 -17 +12 -14 -14 +11 +1 -16 +11 -5 +20 -1 +14 -15 -10 -5 +4 -17 -13 -2 -12 -15 +12 +8 -3 +13 +17 +21 +21 +8 +9 -5 -15 -19 -9 -17 -5 +15 +12 +14 +19 -2 +15 -6 +19 -2 +4 -5 -8 -4 +10 +1 -5 +10 +12 +14 -2 +11 -3 -15 -6 +14 +3 +8 +10 +14 +11 +18 +3 -4 -5 -13 +17 -12 -8 -5 +7 +7 -10 -19 +17 +1 +17 -5 -9 -10 -9 -1 -3 -14 +11 +1 +11 +1 +2 -17 +4 +19 +17 +6 +18 -4 +3 -13 +7 -3 +19 +5 +2 +6 +12 +5 -7 +10 +16 -9 -16 +11 +10 +2 +7 -16 +6 +16 +17 +11 +11 -14 +11 -16 -13 +6 +8 +10 -4 -5 +2 +5 -18 +19 -11 -5 -5 -5 -16 -5 +16 +7 -10 -20 -14 -18 +13 +9 -10 +18 -7 -8 -4 +13 +9 +18 +20 -10 -14 -22 -21 -10 +20 -7 -9 +1 +11 +6 +12 +14 -5 +16 +13 +8 -2 -13 -2 +11 +21 +9 -5 +1 +18 +6 +18 -17 +3 +7 -2 -3 +1 +7 +17 +16 +4 +13 +7 +17 -18 +17 +2 +19 -11 +2 +2 +1 -16 -19 -4 -17 -8 -5 +12 -8 +19 +3 +17 +3 +3 +8 +3 -13 +12 -7 +9 +16 +15 +3 -6 -10 +14 -13 -8 +4 +12 +19 +17 +18 -12 -11 +7 -1 -7 -28 -19 -6 +2 +15 +3 -12 -15 +5 -15 -8 -16 -17 +8 -7 +3 +6 -18 +10 -17 -9 -13 +20 -13 -12 -12 +9 -2 +6 -10 -1 +14 -18 -14 +2 +25 -16 -17 +19 +8 +14 -15 -17 +40 +21 -19 +4 +3 -2 +9 -2 -3 +15 -9 -18 +9 +7 +27 +3 +8 +6 +2 -13 +4 -16 +26 -15 -8 -16 +17 -18 +33 +9 +68 +8 +20 -9 -8 +28 +15 +15 +9 +12 +20 +5 +16 +22 -5 +8 +14 +6 +6 +10 +10 +7 -13 -8 +10 +9 +13 -15 -15 +13 +8 +5 +25 -10 +21 +16 +10 -16 +1 -57 +13 -20 -30 +2 +7 +15 -18 -28 -13 +1 -9 -6 -2 -13 +11 -4 -1 -9 -13 -13 +12 -14 +12 -13 -7 -2 -15 -2 +3 +32 +13 +12 -4 -19 -5 +22 -29 -24 -25 -6 -12 -9 +3 -15 +3 -5 +20 -10 -34 -77 -9 -9 -23 -6 +8 +9 +47 -82 -21 +38 -61 +11 -65 -37 -22 +2 +12 -26 -20 -4 +6 -7 +14 +6 +11 +19 -32 +10 -74 +9 -64 -59 -92 -10 -92 -18 -23 -64754 -2 -16 -6 -19 +6 -12 -10 +14 +9 +11 +12 +15 +2 -14 -11 +13 -1 -18 -3 +19 +16 +12 +14 -19 -11 +9 -7 +13 +20 -1 +2 +13 +10 +15 +15 +13 -15 -7 -10 +9 +2 +7 +18 -9 +6 -8 +4 +18 -17 +12 +14 +14 -15 -12 -17 +18 -16 +6 -13 -23 -5 +9 -10 -16 -19 +1 +12 -18 -9 -1 +5 -9 +11 +1 +1 +17 -20 +5 -17 -13 -9 -18 -11 -19 -13 +11 -4 +19 -5 +9 +18 +8 -12 -10 -14 +17 +20 +12 +15 -22 -12 +9 -5 -19 +18 +19 -8 -23 -18 -1 -4 -16 +1 -16 +19 -11 -19 -8 -15 -12 -4 -15 +10 +3 +15 -19 +11 +5 +8 -19 +3 -18 +4 -8 +1 +5 -13 -20 +7 -8 -2 +16 +13 -8 -12 +2 +3 +13 -9 +15 +9 -16 -1 -21 +8 -17 -6 -2 -18 -10 -6 -13 -19 -1 +10 -3 -9 -9 +8 +2 +17 -3 +5 -6 -17 +13 +16 -10 +3 +12 +15 -13 -12 -23 +10 +16 +3 -14 -6 -14 +11 +13 +20 +8 -15 +19 -10 +1 -6 +14 +13 +7 -15 -1 -5 -3 -19 +4 +7 -13 -12 -19 +4 -2 -15 -1 +10 -13 -1 -10 +7 +11 -1 -9 +14 -9 -15 +14 -7 -15 -16 -14 +12 -5 -5 +11 -5 +7 +18 -1 -14 -14 -1 -12 +1 +1 +6 +18 -11 -12 -14 -2 +1 -3 -20 -8 -8 -3 +17 +7 +4 +21 +19 -10 +6 +20 +16 -17 +7 -11 +7 +8 -2 +20 -14 +21 +4 +3 +3 -7 +23 -17 -24 +5 +15 -27 -10 -2 -12 -23 +2 -25 -11 +19 -30 -17 -15 +2 +16 +8 +10 +1 -15 -10 +9 -18 -17 +23 -15 +17 +6 -19 +15 -7 +2 -15 +21 -24 -15 -4 +14 +2 +18 +34 +6 +8 -19 -6 -12 +3 -15 -12 -37 +2 +9 -22 -31 -5 +1 -16 +19 +10 -19 -22 -14 -6 -18 +10 -6 +17 +18 -19 -15 +3 -16 +20 +10 -19 +10 -6 +20 +19 +11 -17 +13 -20 -4 +20 -18 -12 -8 -18 -18 +6 -2 +5 -17 -7 -12 -5 -9 +11 -9 -11 -12 -4 -4 -1 -2 +14 -13 +17 -12 -19 +23 +12 -5 +16 +15 -9 -12 -11 -17 -17 -6 +22 +21 +12 +19 +13 +22 +19 -11 +2 -7 +8 -12 -18 +6 -5 -13 -34 -11 -1 -4 +20 +63 -4 -14 -24 -20 -31 -90 -8 -9 -21 -16 +27 -19 -9 -183 -3 -10 -16 +9 -10 +11 +11 +19 +32 -2 -3 -81 +12 +16 +5 -1 +17 -28 +32 +22 +39 -115 -2 +183 +108 +1 -19 +14 +3 +39 -10 +33 +14 -161 -885 -63592 -9 -10 +3 -4 -4 +19 +16 +20 +14 -3 -18 -10 -5 -7 +17 -16 +5 -4 -18 +10 +1 +18 +1 +2 -19 -6 -19 -12 -13 -4 +20 -7 +2 -4 +15 -21 -4 -16 -5 +17 -10 +9 -5 +18 +21 -6 +9 -19 -6 +17 -2 -5 +24 +130793"
# operands = tuple(map(int, input.split()))
operands = tuple([int(op) for op in input.split()])
operands_length = len(operands)
last_output = 0
frequencies = [0]
def search():
global last_output
global frequencies
for i, entry in enumerate(operands):
new_output = last_output + entry
if new_output in frequencies:
print("SOLVED:", new_output)
return new_output
else:
frequencies.append(new_output)
last_output = new_output
if i + 1 == operands_length:
search()
start = datetime.datetime.now()
search()
end = datetime.datetime.now()
delta = (end - start).total_seconds()
print('It took', delta, 'seconds to complete this search!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.