(Attempt 2 at posting something like this, kbin was being weird last time)
Link to a YouTube video going through the main part of the newsletter, with links to other stuff in the description: https://youtu.be/wadIR3wjDfQ
M O S S
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).
The prototype chain in JavaScript (and presumably other prototype-based OOP languages) is really quite similar to the scope chain for local variable lookup: first try to find the property/variable in the current object/scope, and if not found, look in the prototype / parent scope until we reach the outermost object/scope.
I’ve been thinking for quite a while now about the idea of a language that merges these two concepts into one. I’m not ready to talk about it much yet – it’s still very much in the planning phase, but I’m planning to post about it if and when I make significant progress on it.
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))