5 kyu
All that is open must be closed...
700 of 1,516ChristianECooper
Description:
Background
We all know about "balancing parentheses" (plus brackets, braces and chevrons) and even balancing characters that are identical.
Read that last sentence again, I balanced different characters and identical characters twice and you didn't even notice... :)
Kata
Your challenge in this kata is to write a piece of code to validate that a supplied string is balanced.
You must determine if all that is open is then closed, and nothing is closed which is not already open!
You will be given a string to validate, and a second string, where each pair of characters defines an opening and closing sequence that needs balancing.
You may assume that the second string always has an even number of characters.
Example
# In this case '(' opens a section, and ')' closes a section
is_balanced("(Sensei says yes!)", "()") # => True
is_balanced("(Sensei says no!", "()") # => False
# In this case '(' and '[' open a section, while ')' and ']' close a section
is_balanced("(Sensei [says] yes!)", "()[]") # => True
is_balanced("(Sensei [says) no!]", "()[]") # => False
# In this case a single quote (') both opens and closes a section
is_balanced("Sensei says 'yes'!", "''") # => True
is_balanced("Sensei say's no!", "''") # => False
Stacks
Parsing
Algorithms
Regular Expressions
Similar Kata:
Stats:
Created | May 28, 2015 |
Published | May 29, 2015 |
Warriors Trained | 5061 |
Total Skips | 867 |
Total Code Submissions | 18676 |
Total Times Completed | 1516 |
Python Completions | 700 |
JavaScript Completions | 661 |
CoffeeScript Completions | 14 |
C# Completions | 188 |
Total Stars | 158 |
% of votes with a positive feedback rating | 91% of 278 |
Total "Very Satisfied" Votes | 240 |
Total "Somewhat Satisfied" Votes | 28 |
Total "Not Satisfied" Votes | 10 |