Skip to main content
Commonmark migration
Source Link

#MATL, 12 11 bytes

MATL, 12 11 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display

#MATL, 12 11 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display

MATL, 12 11 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display
edited body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

#MATL, 11 12 11 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display

#MATL, 11 12 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display

#MATL, 12 11 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display
added 71 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

#MATL, 1211 12 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

2*81-Ys1=f11_j^Ys0<f1)

Try it online!Try it online!

2*1_         % implicitnumber input.-1
j Transforms each '(' into 80 and each ')' into 82
81-% take string input
^     % subtract 81. Gives array with% element-1wise forpower. This transforms '(' and to 1 forand ')' to -1
Ys         % cumulative sum
1=0<         % true for values that equalnegative 1values
f          % find all such values 
1)         % pick first. Implicit display

#MATL, 12 bytes

2*81-Ys1=f1)

Try it online!

2*         % implicit input. Transforms each '(' into 80 and each ')' into 82
81-        % subtract 81. Gives array with -1 for '(' and 1 for ')'
Ys         % cumulative sum
1=         % true for values that equal 1
f          % find all such values 
1)         % pick first. Implicit display

#MATL, 11 12 bytes

1 byte saved using Dennis' idea of computing -1 raised to the input string

1_j^Ys0<f1)

Try it online!

1_         % number -1
j          % take string input
^          % element-wise power. This transforms '('  to 1 and ')' to -1
Ys         % cumulative sum
0<         % true for negative values
f          % find all such values 
1)         % pick first. Implicit display
added 213 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
added 213 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading