Compare commits
No commits in common. "3e5502e3d872ec6c7883fc87f692cf2d3b5ef82b" and "1392358ada5bd39241cd6b353e1685ce67b67016" have entirely different histories.
3e5502e3d8
...
1392358ada
|
@ -1,34 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
|
|
||||||
def solve(input: list[int]) -> int:
|
|
||||||
def mix(file: list[int]) -> list[int]:
|
|
||||||
shuffled = deque(enumerate(file))
|
|
||||||
|
|
||||||
for i, n in enumerate(file):
|
|
||||||
item = shuffled.index((i, n))
|
|
||||||
shuffled.remove((i, n))
|
|
||||||
# Moving the item to the left means moving the collection to the left
|
|
||||||
shuffled.rotate(-n)
|
|
||||||
shuffled.insert(item, (i, n))
|
|
||||||
|
|
||||||
return [n for _, n in shuffled]
|
|
||||||
|
|
||||||
def coordinates(file: list[int]) -> tuple[int, int, int]:
|
|
||||||
zero_index = file.index(0)
|
|
||||||
indices = map(lambda n: n + zero_index, [1000, 2000, 3000])
|
|
||||||
return tuple(map(lambda n: file[n % len(file)], indices)) # type: ignore
|
|
||||||
|
|
||||||
return sum(coordinates(mix(input)))
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
input = [int(n) for n in sys.stdin.readlines()]
|
|
||||||
print(solve(input))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
5000
2022/d20/ex1/input
5000
2022/d20/ex1/input
File diff suppressed because it is too large
Load diff
|
@ -1,37 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
|
|
||||||
def solve(input: list[int]) -> int:
|
|
||||||
def mix(file: list[int], rounds: int) -> list[int]:
|
|
||||||
shuffled = deque(enumerate(file))
|
|
||||||
|
|
||||||
for _ in range(rounds):
|
|
||||||
for i, n in enumerate(file):
|
|
||||||
item = shuffled.index((i, n))
|
|
||||||
shuffled.remove((i, n))
|
|
||||||
# Moving the item to the left means moving the collection to the left
|
|
||||||
shuffled.rotate(-n)
|
|
||||||
shuffled.insert(item, (i, n))
|
|
||||||
|
|
||||||
return [n for _, n in shuffled]
|
|
||||||
|
|
||||||
def coordinates(file: list[int]) -> tuple[int, int, int]:
|
|
||||||
zero_index = file.index(0)
|
|
||||||
indices = map(lambda n: n + zero_index, [1000, 2000, 3000])
|
|
||||||
return tuple(map(lambda n: file[n % len(file)], indices)) # type: ignore
|
|
||||||
|
|
||||||
file = [n * 811589153 for n in input]
|
|
||||||
file = mix(file, 10)
|
|
||||||
return sum(coordinates(file))
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
input = [int(n) for n in sys.stdin.readlines()]
|
|
||||||
print(solve(input))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
5000
2022/d20/ex2/input
5000
2022/d20/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue