Brain-flak turns one year old tomorrow! In honor of it's birthday, we're having a PPCG style birthday party, where several users post brain-flak related questions! Help us celebrate! :)
Brain-flak is an esoteric language I wrote where all of the commands are brackets and all of the brackets must be fully matched. To borrow my own definition:
For the purpose of this challenge, a "bracket" is any of these characters:
()[]{}<>
.A pair of brackets is considered "matched" if the opening and closing brackets are in the right order and have no characters inside of them, such as
() []{}
Or if every subelement inside of it is also matched.
[()()()()] {<[]>} (()())
Subelements can also be nested several layers deep.
[(){<><>[()]}<>()] <[{((()))}]>
A string is considered "Fully matched" if and only if:
Every single character is a bracket,
Each pair of brackets has the correct opening and closing bracket and in the right order
In celebration of brain-flak's first birthday, today's challenge is about taking an unbalanced set of brackets, and determining what types of operations are needed to make it valid brain-flak.
For example,
((
is not valid brain-flak code, but if we append))
to it, it becomes(())
, which is fully balanced, and therefore valid brain-flak. That makes this input appendable.Similarly,
>}
is not valid, but we can prepend{<
to it to make{<>}
, which is valid. That makes this input prependable.Some inputs are slightly more complicated. For example,
)][({
cannot be made valid purely by appending or prepending. But it can be made valid by prepending[(
and appending})]
. Therefore, this input is both prependable and appendable.Lastly, some inputs can never be made valid brain-flak code by any combination of appending or prepending. For example,
(>
can never be made valid. (Prepending<
creates<(>
, and appending)
creates(>)
, neither of which are valid) Therefore, this input is neither appendable or prependable.
For today's challenge, you must write a program or function that takes a string of brackets and determines if the string is
appendable
prependable
both
neither
You may pick what values you use to represent for each case. For example, outputting 1, 2, 3, 4
, or 'a', 'p', 'b', 'n'
, or 1, 'foo', 3.1415, -17
, or whatever is fine. As long as each output is distinct and consistent, that's fine. You must however, clearly specify which output corresponds to which case.
You may return this value in whichever format is most convenient (for example, returning from a function, printing to STDOUT, modifying arguments, writing to a file, etc.).
You can assume that the input will never be valid brain-flak or empty.
Examples
The following inputs are all prependable:
))
(((()()())))}
)>}]
()[]{}<>)
These are all appendable:
(({}{})
((((
([]()())(
{<<{
These are all both:
))((
>()[(()){
>{
And these are all neither:
)(}
{(((()()()))>
[}
((((((((((>
((((((((((<>()]
As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!
This challenge is particularly difficult in brain-flak, so maximum brownie points to any and every answer written in brain-flak. :)
maximum brownie points
I think that offering maximum brownie points and cookies instead would encourage Brain-Flaking this challenge more than just brownie points, since I don't think it's trivial at all in any language, let alone Brain-Flak. :P \$\endgroup\$][
is not appendable, as nothing you can append can make it valid. Similarly, it's not prependable. It's... 'insertable'! You can insert it into a string to make the whole valid Brainflak. \$\endgroup\$You can assume that the input will never be valid brain-flak or empty.
\$\endgroup\$