Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
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.
5
votes
Longest Valid Parentheses
><> (Fish), 135 bytes
0:i:0(?v$6p1+00. ;n+1-~~.?&52~\
@$:@02.\~~1-:0>:
>0&:6g2%2*1-&+:0(?v&1-$:@$:@)?^22.
>1+$1+$:{:})?v$d1.
.1f0v!?:-1-$/ .55/
^~~~ \0n;
Try it
Uses the classic paste the input …
1
vote
Remove redundant parentheses
Rust, 408 396 bytes
I made this problem way to hard for myself
let f=|b:&[u8]|->Vec<u8>{let v=(0..).zip(b).scan(vec![],|a,(b,c)|Some(match c{40=>{a.push(b);None}41=>{Some((a.pop()?,b))}_=>None})).flat …
4
votes
Remove redundant parentheses
Python 3.10,194 193 183 177 174 173 165 163 bytes
-1 byte since one string didn't need to be raw
-10 byes by using a recursive function to re-assemble the output rather than regex
-6 bytes thanks to …
23
votes
16
answers
4k
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 are redundant.
A set of parentheses …
10
votes
Can you perform swaps?
Rust, 204 179 147 132 123 98 90 80 bytes
|a,b|a.iter().zip(b).fold([0;3],|[c,d,f],(&e,g)|[c+e+g,d^e^g,f.min(c+d)])==[0;3]
Attempt This Online!
-9 bytes thanks to SUTerliankov
-2 bytes thanks to SUTe …
16
votes
5
answers
441
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 …