Where will your buddies sit?
Pyth, 39 38 bytes
L@+\ASzbuXGyhHyHQzpyQ"It is ""'s turn.
This is based around repeated applications of the find and replace operation, X
. The first bit defines a lookup function, y
, which finds the b
th player in the player order. Then, we repeatedly perform substitutions to find the final seating order, and finally print out whose turn it is.
Amusingly, the code to find the final seating order is shorter (18 bytes) than the code to print whose turn it is (21 bytes).
The code takes the seating string on the first line of STDIN, and the number of turns on the second.
Demonstration.
Explanation:
L@+\ASzbuXGyhHyHQzpyQ"It is ""'s turn.
Implicit:
z = input()
Q = eval(input())
L def y(b): return
+\ASz "A" + sorted(z)
@ b ( )[b]
u Qz reduce for H in range(len(Q)),
G starts as z.
XGyhHyH replace in G y(H+1) with y(H).
pyQ"It is ""'s turn. Print out whose turn it is.
CJam, 49 45 43 bytes
l_'A+$ri{:L2<(erL(+}*1<"
It is "\"'s turn."
I think this works. It just runs the algorithm as is.
Try it online.
Explanation
l Read line (initial seating order)
_'A+$ Copy, add "A" and sort to give bowling order
ri{ }* Do <number of turns> times...
:L Save bowling order as L
2<( Get next and current bowlers
er Replace next with current in seating
L(+ Push bowling order again and update (rotate)
1< Get current bowler from start of bowling order
"
It is "\"'s turn." Output message
Python 3, 110
s=input()
S=sorted(s+'A')*999
exec("y,*S=S;s=s.replace(S[0],y);"*int(input()))
print(s+"\nIt is %s's turn."%y)
An optimized version of Sp3000's solution using replace
. The list S
cycles though the letters present in order. We perform repeated replacements in the given string of each character of S
by the previous one.