Advertisement
Guest User

AOC Day 20 part 2

a guest
Dec 20th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. with open("2022_20input.txt", 'r') as file:
  2.     input_lines = file.read().split('\n')
  3.     length = len(input_lines)
  4.     for i, value in enumerate(input_lines):
  5.         code[i] = (int(value) * 811589153, i, (int(value) * 811589153) % (length - 1))
  6.  
  7. for mix in range(10):
  8.     print("Mixing...")
  9.     for i in range(length):
  10.         value, position, modval = code[i]
  11.         newposition = (position + modval) % (length - 1)
  12.         if newposition > position:
  13.             up = True
  14.         else:
  15.             up = False
  16.         code[i] = (value, newposition, modval)
  17.         for j, args in code.items():
  18.             if j != i:
  19.                 othervalue, otherpos, othermodval = args
  20.                 if up:
  21.                     if otherpos > position and otherpos <= newposition:
  22.                         code[j] = (othervalue, otherpos - 1, othermodval)
  23.                 else:
  24.                     if otherpos < position and otherpos >= newposition:
  25.                         code[j] = (othervalue, otherpos + 1, othermodval)
  26.                    
  27. # find 1000, 2000 and 3000
  28. zeroposition = next(iter([pos for value, pos, modval in code.values() if value == 0]))
  29. print(zeroposition)
  30. answer = 0
  31. for i in [1000, 2000, 3000]:
  32.     seek = ((i + zeroposition) % length)
  33.     found = next(iter([value for value, pos, modval in code.values() if pos == seek]))
  34.     print(found)
  35.     answer += found
  36. print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement