my solutions for advent of code 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

with open('input20.txt','r') as f:
inp = f.read().splitlines(keepends=False)
sequence = []
for i in range(len(inp)):
if int(inp[i]) == 0:
zero = (i, int(inp[i]))
sequence.append((i, int(inp[i])))
numbers = sequence.copy()
for number in sequence:
if sequence.count(number) > 1:
print('!')
for number in numbers:
#print(number[0])
index = sequence.index(number)
_number = number[1]
newIndex = index + _number
while not (len(sequence) * -1) <= newIndex < len(sequence):
if newIndex < (len(sequence) * -1):
newIndex += len(sequence)
if newIndex >= len(sequence):
newIndex -= len(sequence) - 1
if newIndex == 0:
newIndex = len(sequence) - 1
elif newIndex < 0:
newIndex = len(sequence) -1 + newIndex
if _number >= len(sequence):
newIndex += 1
if _number <= (len(sequence)* -1):
newIndex -= 1
if newIndex > index:
newIndex += 1
sequence.insert(newIndex, number)
sequence.pop(index)
else:
sequence.pop(index)
sequence.insert(newIndex, number)
#print(sequence)
number = sequence.index(zero) + 1000
_sum = 0
for i in range(3):
number %= len(sequence)
#print(sequence[number])
_sum += sequence[number][1]
number += 1000
print(_sum)