Skip to main content
added 239 characters in body
Source Link
Command Master
  • 10.7k
  • 1
  • 11
  • 73

05AB1E, 23 2121 20 bytes

-23 thanks to @Kevin Cruijssen

',¡.œ',δý.ΔεSžuS¢ιËΔεžuS¢ιË}P

Try it online!Try it online!

Try all testcases.Try all testcases.

Explanation

',        push a comma
¡         and split the implicit input by it
.œ        push all partitions, all possible ways to split it to continuous parts
',δý      and join each partition with commas.
.Δ        now keep (and implicitly output) the first partition such that:
 ε        for each of its parts
  žu       push "()<>[]{}"
  S        list of characters, ["(", ")", "<", ...]
  ¢        count each of the characters in the current part
  ι        uninterleave it, put the count of the even indices (opening brackets) and the odd ones (closing brackets) in two lists
  Ë        and check if the two lists are equal - the number of opening brackets of each type is equal to the number of closing ones.
 }
 P        take the product, which functions as and.

05AB1E, 23 21 bytes

-2 thanks to @Kevin Cruijssen

',¡.œ',δý.ΔεSžuS¢ιË}P

Try it online!

Try all testcases.

05AB1E, 23 21 20 bytes

-3 thanks to @Kevin Cruijssen

',¡.œ',δý.ΔεžuS¢ιË}P

Try it online!

Try all testcases.

Explanation

',        push a comma
¡         and split the implicit input by it
.œ        push all partitions, all possible ways to split it to continuous parts
',δý      and join each partition with commas.
.Δ        now keep (and implicitly output) the first partition such that:
 ε        for each of its parts
  žu       push "()<>[]{}"
  S        list of characters, ["(", ")", "<", ...]
  ¢        count each of the characters in the current part
  ι        uninterleave it, put the count of the even indices (opening brackets) and the odd ones (closing brackets) in two lists
  Ë        and check if the two lists are equal - the number of opening brackets of each type is equal to the number of closing ones.
 }
 P        take the product, which functions as and.
added 239 characters in body
Source Link
Command Master
  • 10.7k
  • 1
  • 11
  • 73

05AB1E, 2323 21 bytes

-2 thanks to @Kevin Cruijssen

',¡DεžuS¢ιOÆ}¡.¥>Å¡¦'œ',δý.ΔεSžuS¢ιË}P

Try it online!Try it online!

Try all testcases.

05AB1E, 23 bytes

',¡DεžuS¢ιOÆ}.¥>Å¡¦',δý

Try it online!

05AB1E, 23 21 bytes

-2 thanks to @Kevin Cruijssen

',¡.œ',δý.ΔεSžuS¢ιË}P

Try it online!

Try all testcases.

Source Link
Command Master
  • 10.7k
  • 1
  • 11
  • 73

05AB1E, 23 bytes

',¡DεžuS¢ιOÆ}.¥>Å¡¦',δý

Try it online!