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 ...
23
votes
12
answers
7k
views
How long is this string, really?
In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to ...
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 ...
19
votes
23
answers
3k
views
Split a string on unnested commas
Create the shortest program/function/whatever that splits an inputted string along un-nested commas. A comma is considered nested if it is either within parentheses, brackets, or braces.
Input and ...
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 ...
15
votes
20
answers
3k
views
Longest Valid Parentheses
Given a string of parentheses ( and ), find the length of the longest substring that forms a valid pair of parentheses.
Valid ...
16
votes
5
answers
504
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 ...
10
votes
9
answers
620
views
CGCC Rocket Biking
Something I found while looking through some old files. It seemed like a neat idea for a code golf challenge.
The intro
One of the most popular events at the annual Cyclist's Grand Competition for ...
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 ...
20
votes
28
answers
3k
views
Rearrange to a palindrome
Given a string, shuffle it so that it becomes a palindrome.
For example, adadbcc can be arranged into dacbcad, or ...
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:
...
10
votes
6
answers
514
views
Parenthetical Names
Parenthetical names
Your challenge is to build a program that puts parentheses around the 'title' part of names. For example, Sonic the Hedgehog is converted to <...
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 ...
13
votes
9
answers
1k
views
Remove unmatched brackets
Inspired by @AviFS.
Given a string containing brackets, e.g.
[xyz]]abc[[def]hij[
You can parse through it with a stack of brackets. When you find an open bracket, ...
10
votes
6
answers
596
views
The Missing Match
You are given a string of unknown length that contains a varied amount of (, {, [ and their ...
4
votes
2
answers
477
views
Bracket Depth List
Challenge
Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
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 ...
27
votes
7
answers
2k
views
Ungolf my tinylisp code
I like golfing in tinylisp:
(d M(q((x)(i x(i(disp x)0(M x))0
But I also like posting explanations with nicely formatted code:
...
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. ...
29
votes
31
answers
4k
views
Open or Close the Parentheses
Every phone needs a calculator app. Because of the limited screen real estate, the developer of mine has decided to save some buttons. Instead of having two dedicated bracket buttons - one for open <...
12
votes
1
answer
854
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 ...
17
votes
22
answers
2k
views
Parentheses Clusters
Write a program that groups a string into parentheses cluster. Each cluster should be balanced.
Examples :
...
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
13
answers
2k
views
Remove All Smalltalk Comments for Code Golf
Take a line of input (function arguments or stdin, etc.).
Remove comments in it, where a comment starts and ends with ".
Do not remove comments in string ...
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 ...
16
votes
14
answers
1k
views
A bracket amphitheater
Specification
Write the shortest possible code in any language that does the following:
It takes two arguments, x and y, and generates x + y lines of text.
The first x lines should consist of y nested ...
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 ...
2
votes
0
answers
86
views
Find the number of parenthesis combinations [duplicate]
For example, given 3 sets of parenthesis, you have:
()()()
((()))
()(())
(())()
(()())
= 5 possible combinations.
Challenge
Program must:
• Take 1 number as an ...
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 ...
1
vote
0
answers
53
views
Bracket Checker [duplicate]
Given a string of brackets tell the user whether or not the brackets are well matched or not. Brackets include []{}(). For example:
...
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
4
answers
648
views
Keta Bracket Autocompletion
Special thanks to Bubbler and AdmBorkBork for supplying feedback about this challenge
Keta (Keyboard tacit — clever naming, I know!) is a golfing language I’ve been working on recently. One of it’s ...
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 ...
15
votes
22
answers
4k
views
Test if a string is parenthesly balanced
We call a parens group the open paren (, its matching close paren ) and everything inside them.
A parens group or string is ...
6
votes
2
answers
240
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
...
29
votes
27
answers
3k
views
Detect Perfect Pairings
Let's have a function \$f\$ that takes a string and removes all pairs of adjacent identical characters. For example
\$f(a\color{red}{bb}ba\color{red}{cc}) = aba\$
Note that when two pairs overlap ...
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 ...
28
votes
12
answers
2k
views
Expand compressed brain-flak
This challenge was posted as part of the April 2018 LotM challenge, as well as for Brain-flak's 2nd birthday
I was thinking about what the most efficient way to encode brain-flak programs would be. ...
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!
...
14
votes
3
answers
563
views
Flatten a Stack Cats program
Stack Cats is a reversible, stack-based language. Its reversible nature makes for somewhat weird loops. This challenge is about the conditional loop (...). When ...
18
votes
9
answers
715
views
Fill in the Bracks
Normal brackets ((),[],<> and {}) are nice and ...
8
votes
2
answers
465
views
Keep Decoding This Number!
This challenge posed an algorithm for encoding an integer n as another integer r. What follows is a succinct explanation of that ...
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 ...
24
votes
3
answers
1k
views
Clearly parenthesize APL trains
In APL, you can write tacit functions, called trains. How they work is irrelevant for this challenge. Here are the different ways they can be grouped, using ⍴ as ...
13
votes
7
answers
507
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 ...
27
votes
5
answers
770
views
Bubble the brackets!
There are a few questions on this site about balancing brackets, and checking whether brackets are balanced. I propose it's now time to use those balanced brackets for something!
In mathematics and ...
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 ...
43
votes
25
answers
4k
views
(A[l(t[e(r)n]e)s]t) a string!
Alternesting, is the act of taking a string and nesting it in alternating brackets. Here is how you alternest a string.
For a string of length N, take the center N characters, and surround them in ...
13
votes
3
answers
374
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 ...
3
votes
17
answers
3k
views
Is there an unmatched parenthesis in this String?
Introduction
Given a String containing an arithmetic expression, your task is to output a truthy or falsey value based on whether it contains unmatched parentheses.
Input
Your program should take in ...