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.
105 questions
14
votes
11
answers
1k
views
Counting Rota-Baxter words
A Rota-Baxter word, \$w\$, is a string made of the symbols a, (, and ) such that the ...
15
votes
17
answers
2k
views
Can you perform swaps?
Today's problem is easy. You're given two strings A and B of equal length consisting of only the characters ( and ). Check ...
10
votes
10
answers
1k
views
Language Word Checker
Develop a program to check if a given word is part of a language defined by the following rules:
The language has a set of rules.
The empty string is considered a valid word in the language.
Two ...
16
votes
5
answers
501
views
Flip the order of operations
Scientists have made contact with a parallel universe. Just one problem: They write math differently. Help the scientists make a program that can convert normal math expressions to their equivalent in ...
23
votes
16
answers
5k
views
Remove redundant parentheses
Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that ...
18
votes
26
answers
2k
views
Is it a valid list?
Given a string like [[[],[[]]],[]], made of only commas and square brackets, your challenge is to determine whether it represents a list.
A list is either:
...
16
votes
23
answers
2k
views
Pair my brackets
Given a string consisting of ()[]{}, print the paired brackets in the same order as they appear in the string.
Any opening bracket ...
10
votes
6
answers
594
views
The Missing Match
You are given a string of unknown length that contains a varied amount of (, {, [ and their ...
28
votes
18
answers
2k
views
Find the index of the matching parentheses for each character
The challenge is simple, find the matching parentheses for every one of the parentheses in a given string input
E.g.
()()() -> [1, 0, 3, 2, 5, 4]
Always start ...
16
votes
18
answers
1k
views
AoCG2021 Day 11: Garbageful streams
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2017 Day 9.
Weekends are Bubbler's days off from posting these lol
A large stream blocks your path. ...
12
votes
1
answer
850
views
Lean golf: Balanced Bracket Sequence
Ungolfed, ugly, horrible proof to help you make progress on this challenge: https://gist.github.com/huynhtrankhanh/dff7036a45073735305caedc891dedf2
A bracket sequence is a string that consists of the ...
21
votes
31
answers
3k
views
Remove oddly nested substrings
Task:
Input will consist of some text, with nested [] separating some of it into nested groups:
...
20
votes
11
answers
4k
views
I'm Lazy: Close my Superparens
Picolisp has a feature called "super parentheses":
Brackets ('[' and ']') can be used as super parentheses. A closing bracket will match [all parentheses to and including] the innermost ...
28
votes
34
answers
3k
views
Rotate brackets until they're balanced
Take the string of brackets ]][][[. When you rotate it to the right once, you get []][][. If you rotate it again, you get ...
4
votes
5
answers
5k
views
Parse a nested parentheses
Objective
Mimic Haskell's reads :: ReadS ().
Or in other words, parse nested parentheses. Since the target type is () (the type ...
18
votes
14
answers
3k
views
Visualize a Recursive Acronym
Background
Famously, the acronym GNU stands for GNU's Not Unix. 1
It's recursive because, after expanding it once, it still ...
14
votes
17
answers
3k
views
Parentheses sequences in lexicographical order
Challenge Taken from here and also here
An n parentheses sequence consists of n (s and n )s.
A valid parentheses sequence is ...
6
votes
2
answers
239
views
What associativity was it again
Non-associative operators (for example the subtraction-operator) often are either left- or right associative, such that one has to write less parentheses. Consider for example the following:
$$
a-b-c
...
25
votes
25
answers
3k
views
Golf A Parentheses Matching Algorithm
You will be given a string s. It is guaranteed that the string has equal and at least one [s and ...
15
votes
11
answers
2k
views
Balanced Zero-One Encoding
Task
Encode a string that entirely consists of uppercase alphabets (A-Z) using only zeros and ones, using your own favorite scheme. But the rule isn't that simple!
...
18
votes
9
answers
715
views
Fill in the Bracks
Normal brackets ((),[],<> and {}) are nice and ...
13
votes
6
answers
414
views
Decode Factor Trees
In case you missed Encode Factor Trees, here is the definition of a Factor Tree:
The empty string is 1.
Concatenation represents multiplication.
A number n enclosed in parentheses (or any ...
13
votes
7
answers
504
views
Encode Factor Trees [duplicate]
I once saw on the xkcd fora a format for expressing numbers in an odd way. In this "factor tree" format:
The empty string is 1.
Concatenation represents multiplication.
A number n enclosed in ...
21
votes
14
answers
2k
views
Turn a string inside out
A balanced string is a string of parentheses () so that every parenthesis is can be matched with another one. More rigorously they are the strings spanned by this ...
13
votes
3
answers
372
views
Quote my quote!
A quotation is "the repetition of one expression as part of another one". In American English, a quotation is surrounded by double-quotation marks ("), as in the previous sentence. However, this rule ...