In Minecraft, pistons are blocks that can move other blocks. However, they can only move at most twelve blocks, and won't work at all if any obsidian is in the way. Also, slime blocks are sticky and stick to other blocks, except for obsidian.
Your challenge
Take as input a 5x5 matrix or similar, containing one piston at the bottom, and output the result of the single piston pushing upwards, as 5x6. Input format should have five distinct values for obsidian, slime, other block, piston and empty space, here represented by O
, S
,B
,P
, and
respectively.
For example, say you start with
B
B
B
B
P
Output the result, if the piston was activated, as 5x6:
B
B
B
B
P
Note that the whole configuration with the piston is moved up, as long as it is legal
Testcases:
BBBBB
BBBBB
SSSSS
S
P
=>
BBBBB
BBBBB
SSSSS
S
P
Because 16 is too many blocks.
SBS
SBS
SBS
SBS
P
=>
B
SBS
SBS
SBS
SPS
Because slime sticks to blocks, but blocks don't stick to slime.
O
SSSSS
S
S
P
=>
O
SSSSS
S
S
P
Because the obsidian is in the way, the whole thing can't move.
S S S
S S S
S P S
=>
S S S
S S S
P
S S
The stray blocks stay where they are.
SSSSS
B S B
B S B
B S B
B P B
=>
SSSSS
B S B
S
B S B
B P B
B B
The slime pulls the first two blocks, but the rest stay in place.
OSO
OSO
OSO
OSO
OPO
=>
S
OSO
OSO
OSO
OPO
O O
Slime doesn't stick to obsidian, so it's free to move.
Scoring
This is code-golf, the shorter the better!