Here's an O(n) solution using a stack instead of repeated search & replace:
closing_to_opening = {')': '(', ']': '[', '}': '{'}
brackets = input()
acc = []
for bracket in brackets:
if bracket in closing_to_opening:
if acc and acc[-1] == closing_to_opening[bracket]:
acc.pop()
else:
acc.append(bracket)
else:
acc.append(bracket)
print(''.join(acc))
Haven't thoroughly thought the problem through (so I'm not 100% confident in the correctness of the solution), but the general intuition here is that pairs of brackets can only match up if they only have other matching pairs of brackets between them. You can deal with matching pairs of brackets on the fly simply by removing them, so there's actually no need for backtracking.
Golfed, just for fun:
a=[]
[a.pop()if a and a[-1]==dict(zip(')]}','([{')).get(b)else a.append(b)for b in input()]
print(''.join(a))
They're certainly a rather interesting character. Both for the audience and, in a different way, presumably for the people in their life (Noelle and Toriel in particular).
[Easy] Bracket Simplification
Welcome to the first programming challenge! Three of these will be posted a week and you can complete it in any language you want....
The summer newsletter is out!
Discuss below. I personally find the prospect of Papyrus’ having touched grass… intriguing.
What do you think about Kris? (media.kbin.social)
Reversing the controls for the teacup ride
I haven't actually played Deltarune in quite a long time, but this community needs some more posts, and I'd like to do my part for that....