Browse Source

🐱

master
Roderic Day 5 years ago
parent
commit
61f6c4df2f
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      y2019/p22.py

+ 22
- 0
y2019/p22.py View File

@@ -0,0 +1,22 @@
import sys


def shuffle(text, L, P):
cards = list(range(L))
for line in text.splitlines():
inst, n = line.rsplit(' ', 1)
if inst == 'deal with increment':
n = int(n)
invmod = pow(n, -1, L) # pow(n, L - 2, L)
source = lambda i: i * invmod % L # noqa
elif inst == 'cut':
n = int(n)
source = lambda i: (i + n) % L # noqa
elif inst == 'deal into new':
source = lambda i: (L - 1 - i) % L # noqa
cards = [cards[source(i)] for i in range(L)]
return cards.index(P)


text = sys.stdin.read()
print(shuffle(text, 10007, 2019))

Loading…
Cancel
Save