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.
25
votes
8answers
1k views
Build a nest
The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array.
The rules
Your code must produce a unique valid nested array for every ...
7
votes
3answers
338 views
Two Symbol Math
Introduction
The four basic math operators (+, -, *, /) can be reduced to just two, due to the fact that:
x + y = x - (-y)
x * y = x / (1/y), y != 0
x * 0 = 0/x
Challenge
The challenge is to take ...
7
votes
7answers
343 views
Decompose string into blocks
Your program's input is a string containing whitespaces, parentheses, and other characters. The string is assumed to be parenthesed correctly, i.e. each right parenthesis matches a unique left ...
44
votes
18answers
9k views
Can Pac-Man Eat This String?
In the arcade version of the game, Pac-Man eats pac-dots. However, in this challenge, he's hungry for alphanumeric characters and punctuation in a string.
Your task is to create a function that feeds ...
5
votes
11answers
827 views
Recursion bracketed; or Dyck words generation
We already have challenges to check if a string of brackets is fully matched and to count the number of balanced strings. It remains for us to generate these strings, but it will not be so easy…
A ...
12
votes
8answers
431 views
Autonest an array
Everybody loves nested lists! However, sometimes it's hard to make a nested list. You have to decide if you want to nest it deeper, or if you need to nest it shallower. So for your challenge, you must ...
9
votes
13answers
875 views
Are the two sets equal
{}is the empty set. You may use () or [] if you choose.
We aren't going to rigorously define "set", but sets all satisfy the following properties:
Sets follow the usual mathematical structure. Here ...
11
votes
4answers
518 views
Write a brain-flak interpreter!
Brain-Flak (a cross between Brainf**k and Flack-Overstow) is a stack-based esoteric language. You must write a program or function that takes a string of Brain-Flak code, and evaluates it. It will ...
35
votes
18answers
3k views
Are the brackets fully matched?
You must write a program or function that takes a string of brackets and outputs whether or not that string is fully matched. Your program should print a truthy or falsy value, and IO can be in any ...
12
votes
1answer
286 views
Are there brackets in disguise?
Someone's given us a string, but all bracket-like characters have been changed into normal ones, and we don't know which, or even how many there were. All we know is that if L1,L2,L3,...,LN were ...
24
votes
1answer
398 views
Reverse Engineer Bracket Rectangles
Every programmer knows that rectangles □ are really fun. To exacerbate this fun, these cute and fuzzy diagrams can be transformed into groups of interwoven brackets.
This challenge is the inverse of ...
33
votes
5answers
970 views
Make Bracket Squares
Every programmer knows that brackets []{}()<> are really fun. To exacerbate this fun, groups of interwoven brackets can be transformed into cute and fuzzy diagrams.
Let's say that you have a ...
19
votes
3answers
561 views
Parenthesize an expression
Recently I've been writing a new language, to avoid needing to handle order of operations, I simply parenthesize each expression properly to avoid this entirely.
Because parenthesis are at char-...
26
votes
13answers
2k views
Motzkin Numbers
The nth Motzkin Number is the number of paths from (0, 0) to (n, 0) where each step is of the form (1, -1), (1, 0) or (1, 1), and the path never goes below y = 0.
Here's an illustration of these ...
32
votes
39answers
5k views
Catalan Numbers
The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics.
The nth Catalan number is the number of Dyck words (balanced strings of parenthesis or brackets such as ...
24
votes
3answers
2k views
Generating Brainf*** NOPs
Sometimes when writing brainfuck code, you feel the need to make it longer than needed to encourage debugging. You could do it by just plopping a >< in there, but what fun is that? You'll need ...
17
votes
10answers
1k views
Bracket balancing
You will be given a (possibly empty) string containing brackets ([{()}]) and any other characters (A-Z, a-z, 0-9, punctuation). You need to check if it adheres to the following rules:
Non-bracket ...
10
votes
2answers
184 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 ...
26
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 0 with a ), then will all the parentheses match?
In most cases they won't. For example, 9 ...
28
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 respective bracket types match. For ...
28
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 ...
30
votes
12answers
2k views
{Curly Numbers};
In the esoteric programming language Curly, programs consist solely of curly braces {} and semicolons ;. Despite this humble toolset, Curly has literals that can represent any nonnegative integer. The ...
37
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 ...
19
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 matching right parenthesis ).
Every left bracket [ has a matching right ...
17
votes
2answers
450 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 ...
21
votes
9answers
938 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
345 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 0s as 1s.
You are given a positive ...
61
votes
34answers
6k 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 collapsed telescopic construction. So let's ...
31
votes
4answers
1k 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 ...
9
votes
4answers
414 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 ...
16
votes
4answers
1k 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
655 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 one or more pairs of matching ...
29
votes
6answers
3k 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 like it should be, while ())( and ()( ...
15
votes
4answers
1k 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 ...
13
votes
19answers
2k 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 ...
15
votes
1answer
1k 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 over the alphabet A is balanced if
it ...
6
votes
3answers
480 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 ...
18
votes
14answers
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 map of some mountains. Each set of ...
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 ...