Beta

Growing and Shrinking Potions

Description:

There are two types of potions:

  1. Growing potion: "A"
  2. Shrinking potion: "B"
  • If "A" immediately follows a digit, add 1 to the digit.
  • If "B" immediately follows a digit, subtract 1 from the digit.

Create a function that returns a string according to these rules, removing the potions once they've been consumed.

Examples

"3A78B51" ➞ "47751"
# 3 grows to 4, 8 shrinks to 7

"9A999B" ➞ "10998"
# First 9 grows to 10 and second 9 shrinks to 8

"6A123" ➞ "7123"
# 6 grows to 7

"567" ➞ "567"
# No change

Notes

  • Digits that do not have a potion on their immediate right should be left alone.
  • A digit will always either be followed by zero or exactly 1 potion.
  • There won't be any 0 in the given string.
Algorithms
Strings

More By Author:

Check out these other kata created by saudiGuy

Stats:

CreatedAug 30, 2023
PublishedAug 30, 2023
Warriors Trained64
Total Skips1
Total Code Submissions83
Total Times Completed48
Python Completions48
Total Stars1
% of votes with a positive feedback rating87% of 34
Total "Very Satisfied" Votes28
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes3
Total Rank Assessments39
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • saudiGuy Avatar
Ad