Beta
Growing and Shrinking Potions
48saudiGuy
Description:
There are two types of potions:
- Growing potion: "A"
- 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
Similar Kata:
Stats:
Created | Aug 30, 2023 |
Published | Aug 30, 2023 |
Warriors Trained | 64 |
Total Skips | 1 |
Total Code Submissions | 83 |
Total Times Completed | 48 |
Python Completions | 48 |
Total Stars | 1 |
% of votes with a positive feedback rating | 87% of 34 |
Total "Very Satisfied" Votes | 28 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 39 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |