-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Instructions | ||
|
||
Given a string containing brackets `[]`, braces `{}`, parentheses `()`, or any combination thereof, verify that any and all pairs are matched and nested correctly. | ||
Any other characters should be ignored. | ||
For example, `"{what is (42)}?"` is balanced and `"[text}"` is not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Introduction | ||
|
||
You're given the opportunity to write software for the Bracketeer™, an ancient but powerful mainframe. | ||
The software that runs on it is written in a proprietary language. | ||
Much of its syntax is familiar, but you notice _lots_ of brackets, braces and parentheses. | ||
Despite the Bracketeer™ being powerful, it lacks flexibility. | ||
If the source code has any unbalanced brackets, braces or parentheses, the Bracketeer™ crashes and must be rebooted. | ||
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™. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## -*- conf -*- | ||
.rebar3 | ||
_build/ | ||
ebin/ | ||
erl_crash.dump | ||
rebar3.crashdump | ||
|
||
tmp | ||
bin/configlet | ||
bin/configlet.exe | ||
CHECKLIST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"authors": [ | ||
"BNAndras" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/matching-brackets.lfe" | ||
], | ||
"test": [ | ||
"test/matching-brackets-tests.lfe" | ||
], | ||
"example": [ | ||
".meta/example.lfe" | ||
] | ||
}, | ||
"blurb": "Make sure the brackets and braces all match.", | ||
"source": "Ginna Baker" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(defmodule matching-brackets | ||
(export (paired? 1))) | ||
|
||
(include-lib "lfe/include/clj.lfe") | ||
|
||
(defun paired? (string) | ||
(paired-helper string '())) | ||
|
||
(defun paired-helper | ||
(('() '()) | ||
'true) | ||
(('() _) | ||
'false) | ||
(((cons #\{ string) stack) | ||
(paired-helper string (cons #\{ stack))) | ||
(((cons #\[ string) stack) | ||
(paired-helper string (cons #\[ stack))) | ||
(((cons #\( string) stack) | ||
(paired-helper string (cons #\( stack))) | ||
(((cons #\} string) (cons #\{ stack)) | ||
(paired-helper string stack)) | ||
(((cons #\] string) (cons #\[ stack)) | ||
(paired-helper string stack)) | ||
(((cons #\) string) (cons #\( stack)) | ||
(paired-helper string stack)) | ||
(((cons #\} _) _) | ||
'false) | ||
(((cons #\] _) _) | ||
'false) | ||
(((cons #\) _) _) | ||
'false) | ||
(((cons _ string) stack) | ||
(paired-helper string stack))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[81ec11da-38dd-442a-bcf9-3de7754609a5] | ||
description = "paired square brackets" | ||
|
||
[287f0167-ac60-4b64-8452-a0aa8f4e5238] | ||
description = "empty string" | ||
|
||
[6c3615a3-df01-4130-a731-8ef5f5d78dac] | ||
description = "unpaired brackets" | ||
|
||
[9d414171-9b98-4cac-a4e5-941039a97a77] | ||
description = "wrong ordered brackets" | ||
|
||
[f0f97c94-a149-4736-bc61-f2c5148ffb85] | ||
description = "wrong closing bracket" | ||
|
||
[754468e0-4696-4582-a30e-534d47d69756] | ||
description = "paired with whitespace" | ||
|
||
[ba84f6ee-8164-434a-9c3e-b02c7f8e8545] | ||
description = "partially paired brackets" | ||
|
||
[3c86c897-5ff3-4a2b-ad9b-47ac3a30651d] | ||
description = "simple nested brackets" | ||
|
||
[2d137f2c-a19e-4993-9830-83967a2d4726] | ||
description = "several paired brackets" | ||
|
||
[2e1f7b56-c137-4c92-9781-958638885a44] | ||
description = "paired and nested brackets" | ||
|
||
[84f6233b-e0f7-4077-8966-8085d295c19b] | ||
description = "unopened closing brackets" | ||
|
||
[9b18c67d-7595-4982-b2c5-4cb949745d49] | ||
description = "unpaired and nested brackets" | ||
|
||
[a0205e34-c2ac-49e6-a88a-899508d7d68e] | ||
description = "paired and wrong nested brackets" | ||
|
||
[1d5c093f-fc84-41fb-8c2a-e052f9581602] | ||
description = "paired and wrong nested brackets but innermost are correct" | ||
|
||
[ef47c21b-bcfd-4998-844c-7ad5daad90a8] | ||
description = "paired and incomplete brackets" | ||
|
||
[a4675a40-a8be-4fc2-bc47-2a282ce6edbe] | ||
description = "too many closing brackets" | ||
|
||
[a345a753-d889-4b7e-99ae-34ac85910d1a] | ||
description = "early unexpected brackets" | ||
|
||
[21f81d61-1608-465a-b850-baa44c5def83] | ||
description = "early mismatched brackets" | ||
|
||
[99255f93-261b-4435-a352-02bdecc9bdf2] | ||
description = "math expression" | ||
|
||
[8e357d79-f302-469a-8515-2561877256a1] | ||
description = "complex latex expression" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
ERL := $(shell which erl) | ||
REBAR3 := $(shell which rebar3) | ||
|
||
null := | ||
space := $(null) # | ||
comma := , | ||
|
||
ifeq ($(ERL),) | ||
$(error Can't find Erlang executable 'erl') | ||
else ifeq ($(REBAR3),) | ||
$(error Can't find rebar3) | ||
endif | ||
|
||
compile: ; $(REBAR3) compile | ||
|
||
clean: ; $(REBAR3) clean | ||
|
||
.PHONY: test | ||
test: | ||
$(REBAR3) eunit \ | ||
-m $(subst $(space),$(comma),$(basename $(notdir $(wildcard test/*.lfe)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{plugins, [{rebar3_lfe, "0.4.10"}]}. | ||
|
||
{provider_hooks, [{post, [{compile, {lfe, compile}}]}]}. | ||
|
||
{deps, [{lfe, "2.1.3"}]}. | ||
|
||
{profiles, | ||
[{test, | ||
[{eunit_compile_opts, [{src_dirs, ["src", "test"]}]}, | ||
{deps, | ||
[{ltest, "0.13.8"}]}]}]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{"1.2.0", | ||
[{<<"lfe">>,{pkg,<<"lfe">>,<<"2.1.3">>},0}]}. | ||
[ | ||
{pkg_hash,[ | ||
{<<"lfe">>, <<"6EFCB2BBC1FFC21DC5D1C092F00EFDB397EAC889474AC5C86EDF78A3557CC730">>}]}, | ||
{pkg_hash_ext,[ | ||
{<<"lfe">>, <<"4E4BAD515A169AE418FEB7374EA1C8D741FAEA9D95E266CE343B45BCC377F55B">>}]} | ||
]. |
11 changes: 11 additions & 0 deletions
11
exercises/practice/matching-brackets/src/matching-brackets.app.src
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%% -*- erlang -*- | ||
{application, 'matching-brackets', | ||
[{description, ""}, | ||
{vsn, "0.0.1"}, | ||
{modules, | ||
['matching-brackets']}, | ||
{registered, []}, | ||
{applications, | ||
[kernel, stdlib]}, | ||
{included_applications, []}, | ||
{env, []}]}. |
4 changes: 4 additions & 0 deletions
4
exercises/practice/matching-brackets/src/matching-brackets.lfe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(defmodule matching-brackets | ||
(export (paired? 1))) | ||
|
||
; Please implement the paired? function. |
66 changes: 66 additions & 0 deletions
66
exercises/practice/matching-brackets/test/matching-brackets-tests.lfe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(defmodule matching-brackets-tests | ||
(behaviour ltest-unit) | ||
(export all)) | ||
|
||
(include-lib "ltest/include/ltest-macros.lfe") | ||
|
||
(deftest paired-square-brackets | ||
(is (matching-brackets:paired? "[]"))) | ||
|
||
(deftest empty-string | ||
(is (matching-brackets:paired? ""))) | ||
|
||
(deftest unpaired-brackets | ||
(is-not (matching-brackets:paired? "[["))) | ||
|
||
(deftest wrong-ordered-brackets | ||
(is-not (matching-brackets:paired? "}{"))) | ||
|
||
(deftest wrong-closing-bracket | ||
(is-not (matching-brackets:paired? "{]"))) | ||
|
||
(deftest paired-with-whitespace | ||
(is (matching-brackets:paired? "{ }"))) | ||
|
||
(deftest partially-paired-brackets | ||
(is-not (matching-brackets:paired? "{[])"))) | ||
|
||
(deftest simple-nested-brackets | ||
(is (matching-brackets:paired? "{[]}"))) | ||
|
||
(deftest several-paired-brackets | ||
(is (matching-brackets:paired? "{}[]"))) | ||
|
||
(deftest paired-and-nested-brackets | ||
(is (matching-brackets:paired? "([{}({}[])])"))) | ||
|
||
(deftest unopened-closing-brackets | ||
(is-not (matching-brackets:paired? "{[)][]}"))) | ||
|
||
(deftest unpaired-and-nested-brackets | ||
(is-not (matching-brackets:paired? "([{])"))) | ||
|
||
(deftest paired-and-wrong-nested-brackets | ||
(is-not (matching-brackets:paired? "[({]})"))) | ||
|
||
(deftest paired-and-wrong-nested-brackets-but-innermost-are-correct | ||
(is-not (matching-brackets:paired? "[({}])"))) | ||
|
||
(deftest paired-and-incomplete-brackets | ||
(is-not (matching-brackets:paired? "{}["))) | ||
|
||
(deftest too-many-closing-brackets | ||
(is-not (matching-brackets:paired? "[]]"))) | ||
|
||
(deftest early-unexpected-brackets | ||
(is-not (matching-brackets:paired? ")()"))) | ||
|
||
(deftest early-mismatched-brackets | ||
(is-not (matching-brackets:paired? "{)()"))) | ||
|
||
(deftest math-expression | ||
(is (matching-brackets:paired? "(((185 + 223.85) * 15) - 543)/2"))) | ||
|
||
(deftest complex-latex-expression | ||
(let ((expr "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)")) | ||
(is (matching-brackets:paired? expr)))) |