Skip to content

Instantly share code, notes, and snippets.

@adregan
Last active December 11, 2021 00:32
Show Gist options
  • Save adregan/d7600bcd615a8707264b217d5ce12ab2 to your computer and use it in GitHub Desktop.
Save adregan/d7600bcd615a8707264b217d5ce12ab2 to your computer and use it in GitHub Desktop.
import re
from functools import partial
stripPairs = partial(re.sub, "\(\)|\[\]|{}|<>", "")
def untilStable(f, x):
if ((y := f(x)) == x): return x
else: return untilStable(f, y)
navs = [
'[({(<(())[]>[[{[]{<()<>>',
'[(()[<>])]({[<{<<[]>>(',
'{([(<{}[<>[]}>{[]{[(<()>',
'(((({<>}<{<{<>}{[]{[]{}',
'[[<[([]))<([[{}[[()]]]',
'[{[{({}]{}}([{[{{{}}([]',
'{<[[]]>}<{[{[{[]{()[[[]',
'[<(<(<(<{}))><([]([]()',
'<{([([[(<>()){}]>(<<{{',
'<{([{{}}[<[[[<>{}]]]>[]]'
]
res = [untilStable(stripPairs, n) for n in navs]
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment