Skip to main content

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
14 votes
11 answers
1k views

A Rota-Baxter word, \$w\$, is a string made of the symbols a, (, and ) such that the ...
Wheat Wizard's user avatar
  • 103k
23 votes
12 answers
7k views

In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to ...
emanresu A's user avatar
  • 46.2k
15 votes
17 answers
2k views

Today's problem is easy. You're given two strings A and B of equal length consisting of only the characters ( and ). Check ...
Huỳnh Trần Khanh's user avatar
19 votes
23 answers
3k views

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 ...
Dadsdy's user avatar
  • 2,105
10 votes
10 answers
1k views

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 ...
Huỳnh Trần Khanh's user avatar
15 votes
20 answers
3k views

Given a string of parentheses ( and ), find the length of the longest substring that forms a valid pair of parentheses. Valid ...
aitzazisstuffed's user avatar
16 votes
5 answers
504 views

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 ...
mousetail's user avatar
  • 14.4k
10 votes
9 answers
620 views

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 ...
mindoverflow's user avatar
  • 1,083
23 votes
16 answers
5k views

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 ...
mousetail's user avatar
  • 14.4k
20 votes
28 answers
3k views

Given a string, shuffle it so that it becomes a palindrome. For example, adadbcc can be arranged into dacbcad, or ...
emanresu A's user avatar
  • 46.2k
18 votes
26 answers
2k views

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: ...
emanresu A's user avatar
  • 46.2k
10 votes
6 answers
514 views

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 <...
Hedge Fleming's user avatar
16 votes
23 answers
2k views

Given a string consisting of ()[]{}, print the paired brackets in the same order as they appear in the string. Any opening bracket ...
math scat's user avatar
  • 9,538
13 votes
9 answers
1k views

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, ...
emanresu A's user avatar
  • 46.2k
10 votes
6 answers
596 views

You are given a string of unknown length that contains a varied amount of (, {, [ and their ...
code's user avatar
  • 541
4 votes
2 answers
477 views

Challenge Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
DialFrost's user avatar
  • 5,189
28 votes
18 answers
2k views

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 ...
DialFrost's user avatar
  • 5,189
27 votes
7 answers
2k views

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: ...
DLosc's user avatar
  • 40.7k
16 votes
18 answers
1k views

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. ...
lyxal's user avatar
  • 35.6k
29 votes
31 answers
4k views

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 <...
Jitse's user avatar
  • 8,124
12 votes
1 answer
854 views

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 ...
Huỳnh Trần Khanh's user avatar
17 votes
22 answers
2k views

Write a program that groups a string into parentheses cluster. Each cluster should be balanced. Examples : ...
MSS2001's user avatar
  • 339
21 votes
31 answers
3k views

Task: Input will consist of some text, with nested [] separating some of it into nested groups: ...
rydwolf's user avatar
  • 19.3k
20 votes
13 answers
2k views

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 ...
Wezl's user avatar
  • 1,496
20 votes
11 answers
4k views

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 ...
Wezl's user avatar
  • 1,496
16 votes
14 answers
1k views

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 ...
schuelermine's user avatar
28 votes
34 answers
3k views

Take the string of brackets ]][][[. When you rotate it to the right once, you get []][][. If you rotate it again, you get ...
rydwolf's user avatar
  • 19.3k
2 votes
0 answers
86 views

For example, given 3 sets of parenthesis, you have: ()()() ((())) ()(()) (())() (()()) = 5 possible combinations. Challenge Program must: • Take 1 number as an ...
camila314's user avatar
  • 129
4 votes
5 answers
5k views

Objective Mimic Haskell's reads :: ReadS (). Or in other words, parse nested parentheses. Since the target type is () (the type ...
Dannyu NDos's user avatar
  • 7,381
1 vote
0 answers
53 views

Given a string of brackets tell the user whether or not the brackets are well matched or not. Brackets include []{}(). For example: ...
Ramen_Lover912's user avatar
18 votes
14 answers
3k views

Background Famously, the acronym GNU stands for GNU's Not Unix. 1 It's recursive because, after expanding it once, it still ...
Jonah's user avatar
  • 34.1k
14 votes
4 answers
648 views

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 ...
lyxal's user avatar
  • 35.6k
14 votes
17 answers
3k views

Challenge Taken from here and also here An n parentheses sequence consists of n (s and n )s. A valid parentheses sequence is ...
Luis felipe De jesus Munoz's user avatar
15 votes
22 answers
4k views

We call a parens group the open paren (, its matching close paren ) and everything inside them. A parens group or string is ...
ibrahim mahrir's user avatar
6 votes
2 answers
240 views

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 ...
ბიმო's user avatar
29 votes
27 answers
3k views

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 ...
Wheat Wizard's user avatar
  • 103k
25 votes
25 answers
3k views

You will be given a string s. It is guaranteed that the string has equal and at least one [s and ...
Windmill Cookies's user avatar
28 votes
12 answers
2k views

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. ...
DJMcMayhem's user avatar
  • 60.1k
15 votes
11 answers
2k views

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! ...
Bubbler's user avatar
  • 79.3k
14 votes
3 answers
563 views

Stack Cats is a reversible, stack-based language. Its reversible nature makes for somewhat weird loops. This challenge is about the conditional loop (...). When ...
Martin Ender's user avatar
18 votes
9 answers
715 views

Normal brackets ((),[],<> and {}) are nice and ...
Wheat Wizard's user avatar
  • 103k
8 votes
2 answers
465 views

This challenge posed an algorithm for encoding an integer n as another integer r. What follows is a succinct explanation of that ...
Sherlock9's user avatar
  • 12.4k
13 votes
6 answers
414 views

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 ...
Nissa's user avatar
  • 3,664
24 votes
3 answers
1k views

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 ...
Erik the Outgolfer's user avatar
13 votes
7 answers
507 views

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 ...
Nissa's user avatar
  • 3,664
27 votes
5 answers
770 views

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 ...
Arthur's user avatar
  • 371
21 votes
14 answers
2k views

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 ...
Wheat Wizard's user avatar
  • 103k
43 votes
25 answers
4k views

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 ...
DJMcMayhem's user avatar
  • 60.1k
13 votes
3 answers
374 views

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 ...
musicman523's user avatar
  • 4,812
3 votes
17 answers
3k views

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 ...
Arjun's user avatar
  • 5,174