You come upon a very unusual sight; a group of programs here appear to be dancing.
There are sixteen programs in total, named a
through p
. They start by standing in a line: a
stands in position 0
, b
stands in position 1
, and so on until p
, which stands in position 15
.
The programs' dance consists of a sequence of dance moves:
- Spin, written
sX
, makesX
programs move from the end to the front, but maintain their order otherwise. (For example,s3
onabcde
producescdeab
). - Exchange, written
xA/B
, makes the programs at positionsA
andB
swap places. - Partner, written
pA/B
, makes the programs namedA
andB
swap places.
For example, with only five programs standing in a line (abcde
), they could do the following dance:
s1
, a spin of size1
:eabcd
.x3/4
, swapping the last two programs:eabdc
.pe/b
, swapping programse
andb
:baedc
.
After finishing their dance, the programs end up in order baedc
.
You watch the dance for a while and record their dance moves (your puzzle input). In what order are the programs standing after their dance?