Skip to content

Commit a530d7a

Browse files
Sync matching-brackets (#549)
1 parent 93aa2aa commit a530d7a

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Instructions
22

33
Given a string containing brackets `[]`, braces `{}`, parentheses `()`, or any combination thereof, verify that any and all pairs are matched and nested correctly.
4-
The string may also contain other characters, which for the purposes of this exercise should be ignored.
4+
Any other characters should be ignored.
5+
For example, `"{what is (42)}?"` is balanced and `"[text}"` is not.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Introduction
2+
3+
You're given the opportunity to write software for the Bracketeer™, an ancient but powerful mainframe.
4+
The software that runs on it is written in a proprietary language.
5+
Much of its syntax is familiar, but you notice _lots_ of brackets, braces and parentheses.
6+
Despite the Bracketeer™ being powerful, it lacks flexibility.
7+
If the source code has any unbalanced brackets, braces or parentheses, the Bracketeer™ crashes and must be rebooted.
8+
To avoid such a scenario, you start writing code that can verify that brackets, braces, and parentheses are balanced before attempting to run it on the Bracketeer™.

exercises/practice/matching-brackets/.meta/tests.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[81ec11da-38dd-442a-bcf9-3de7754609a5]
613
description = "paired square brackets"
@@ -41,12 +48,21 @@ description = "unpaired and nested brackets"
4148
[a0205e34-c2ac-49e6-a88a-899508d7d68e]
4249
description = "paired and wrong nested brackets"
4350

51+
[1d5c093f-fc84-41fb-8c2a-e052f9581602]
52+
description = "paired and wrong nested brackets but innermost are correct"
53+
4454
[ef47c21b-bcfd-4998-844c-7ad5daad90a8]
4555
description = "paired and incomplete brackets"
4656

4757
[a4675a40-a8be-4fc2-bc47-2a282ce6edbe]
4858
description = "too many closing brackets"
4959

60+
[a345a753-d889-4b7e-99ae-34ac85910d1a]
61+
description = "early unexpected brackets"
62+
63+
[21f81d61-1608-465a-b850-baa44c5def83]
64+
description = "early mismatched brackets"
65+
5066
[99255f93-261b-4435-a352-02bdecc9bdf2]
5167
description = "math expression"
5268

exercises/practice/matching-brackets/matching-brackets_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ describe('matching-brackets', function()
5454
assert.is_false(brackets.valid('[({]})'))
5555
end)
5656

57+
it('should reject paired and wrong nested brackets but innermost are correct', function()
58+
assert.is_false(brackets.valid('[({}])'))
59+
end)
60+
5761
it('should reject paired and incomplete brackets', function()
5862
assert.is_false(brackets.valid('{}['))
5963
end)
@@ -62,6 +66,14 @@ describe('matching-brackets', function()
6266
assert.is_false(brackets.valid('[]]'))
6367
end)
6468

69+
it('should reject early unexpected brackets', function()
70+
assert.is_false(brackets.valid(')()'))
71+
end)
72+
73+
it('should reject early mismatched brackets', function()
74+
assert.is_false(brackets.valid('{)()'))
75+
end)
76+
6577
it('should accept math expression', function()
6678
assert.is_true(brackets.valid('(((185 + 223.85) * 15) - 543)/2'))
6779
end)

0 commit comments

Comments
 (0)