Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("2022_20input.txt", 'r') as file:
- input_lines = file.read().split('\n')
- length = len(input_lines)
- for i, value in enumerate(input_lines):
- code[i] = (int(value) * 811589153, i, (int(value) * 811589153) % (length - 1))
- for mix in range(10):
- print("Mixing...")
- for i in range(length):
- value, position, modval = code[i]
- newposition = (position + modval) % (length - 1)
- if newposition > position:
- up = True
- else:
- up = False
- code[i] = (value, newposition, modval)
- for j, args in code.items():
- if j != i:
- othervalue, otherpos, othermodval = args
- if up:
- if otherpos > position and otherpos <= newposition:
- code[j] = (othervalue, otherpos - 1, othermodval)
- else:
- if otherpos < position and otherpos >= newposition:
- code[j] = (othervalue, otherpos + 1, othermodval)
- # find 1000, 2000 and 3000
- zeroposition = next(iter([pos for value, pos, modval in code.values() if value == 0]))
- print(zeroposition)
- answer = 0
- for i in [1000, 2000, 3000]:
- seek = ((i + zeroposition) % length)
- found = next(iter([value for value, pos, modval in code.values() if pos == seek]))
- print(found)
- answer += found
- print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement