There are two types of potions:
Growing potion: "A"
Shrinking potion: "B"
- If
"A"
immediately follows a digit, add1
to the proceeding number. - If
"B"
immediately follows a digit, subtract1
from the proceeding number.
Create a function that returns a string according to these rules, removing the potions once they've been consumed.
apply_potions("3A78B51") ➞ "47751"
# 3 grows to 4, 78 shrinks to 77
apply_potions("9999B") ➞ "9998"
apply_potions("9A123") ➞ "10123"
apply_potions("567") ➞ "567"
- Numbers that are not followed by a potion on their immediate right should be left alone.
- A number will always either be followed by zero or exactly 1 potion.