Questions tagged [balanced-string]

In a balanced string certain pairs of characters or substrings always appear with the same amount. Often there are additional restrictions that those pairs also have to be ordered. The most common example is a correctly parenthesized string. See also the [palindrome] and [syntax] tags.

Filter by
Sorted by
Tagged with
20
votes
10answers
2k views

Bracket balancing

You will be given a (possibly empty) string containing brackets ([{()}]) and any other characters (A-...
11
votes
2answers
570 views

Fully parenthesize expressions

Today your challenge is to produce all possible full parenthesizations of an expression. Your input is a single line of printable ASCII containing one or more terms separated by operators. The input ...
25
votes
9answers
1k views

De-Parenthesizing a String

Given a properly-parenthesized string as input, output a list of all nonempty substrings within matching parentheses (or outside of all parentheses), with nested parentheses removed. Each substring ...
28
votes
26answers
2k views

Parenthifiable Binary Numbers

If you express some positive integer in binary with no leading zeros and replace every 1 with a ( and every ...
30
votes
9answers
1k views

Interlocking Brackets

Write a program or function that takes in an eight byte string containing one of each of the characters ()[]{}<> arranged in any way such that the four ...
29
votes
10answers
2k views

Parentheses into Footnotes

Background LISP programmers have taken over the world! Parentheses have been declared as sacred characters, and from now on, they can only be used in LISP programs. It has been decided that ...
33
votes
14answers
3k views

{Curly Numbers};

In the esoteric programming language Curly, programs consist solely of curly braces {} and semicolons ;. Despite this humble ...
41
votes
4answers
2k views

Enumerate valid Brainf**k programs

Golunar/Unary is a way to encode all valid Brainfuck programs, but it is not an enumeration, since most natural numbers do not correspond to a valid program. For the purpose of this challenge, assume ...
20
votes
12answers
1k views

Evaluating Parentheses and Brackets as Integers

Write a program that takes in a string of the four characters ()[] that satisfies these points: Every left parenthesis ( has a ...
15
votes
2answers
650 views

Fix the Braces, etc

Your mission, should you choose to accept it, is to add the minimum number of parentheses, braces, and brackets to make a given string (containing only parentheses, braces, and brackets) have correct ...
23
votes
9answers
1k views

Formatting a Lisp-like Syntax

Background (Based on a true, heart-wrenching story) In my time, I've played around with Lisp and similar languages often. I've written with them, ran them, interpreted them, designed them, and made ...
10
votes
3answers
477 views

Count balanced binary strings matching any of a set of masks

A binary string is a string which contains only characters drawn from 01. A balanced binary string is a binary string which contains exactly as many 0​s as 1​s. You are given a positive ...
79
votes
44answers
7k views

Telescopic Parentheses

Consider a non-empty string of correctly balanced parentheses: (()(()())()((())))(()) We can imagine that each pair of parentheses represents a ring in a ...
32
votes
4answers
2k views

Code Explanation Formatter

Successful code golf submissions are, by nature, filled with crazy symbols all over the place. To make their submission easier to understand, many code-golfers choose to include an explanation of ...
10
votes
4answers
478 views

Prelude Syntax-Checker

Prelude is an esoteric programming language, which has very few, but unusual, restrictions on what constitutes a valid program. Any block of printable ASCII text ("block" meaning that lines of ...
17
votes
4answers
2k views

Write a program which replaces with spaces the braces in cases where braces in places cause stasis

You are a project manager. One day, one of your programmers went insane (not your fault) and took all the expressions in the codebase and added random brackets to them, before quitting on the spot, ...
15
votes
3answers
752 views

Find the shortest bracket numbers

Bracket numbers provide a simple way to express large integers using only left bracket, space, and right bracket ([ ]). A bracket number is defined as a string of ...
39
votes
9answers
5k views

“Convenient palindrome” checker

If you've ever tried to write palindromic code before, you'd know how much brackets tend to get in your way. ()() is not a palindrome, even though it kinda looks ...
17
votes
4answers
2k views

Finish lazy parentheses

The parentheses on my keyboard are all worn out, and I want to avoid using them as much as possible. Your challenge is to balance a line containing parentheses by adding them in before and after each ...
14
votes
19answers
3k views

Fun with Matching Braces [duplicate]

The contest is to make a program or function that takes an arbitrary string resembling source code and checks to see if the "braces" follow the basic rules for brace matching. That is, the number of ...
17
votes
19answers
3k views

Verify Brainfuck program

Yet another Brainfuck parsing problem, but this time... different. You are working in the Infinite Monkeys Incorporated, the company making Brainfuck programs, to solve various interesting problems ...
15
votes
1answer
2k views

Fix unbalanced brackets [duplicate]

Consider the alphabet A ="()[]{}<>". Think of the characters in the alphabet as opening and closing brackets of 4 different types. Let's say that a string ...
7
votes
3answers
606 views

Pretty Printing Parentheses

The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})! So, the goal of this challenge is to make it at least ...
23
votes
15answers
1k views

Topographic Strings

Here is some example input, so I can explain what the problem is: ((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo))) Think of this line of text as a topographic ...
16
votes
23answers
2k views

Indent a string using given parentheses

Given the following input to the program: List of block start characters List of block end characters A string to format format the string with the blocks delimited by the two character sets ...

1 2