News for hackers. Stuff that matters.
Re:A Brutal Look at Balanced Parentheses, Computing Machines... by spc476 on Saturday February 23, 2019 @01:52AM (#19232101)
Are you talking about the interview script, or the programming script? And what if the interviewee brings out Lua and LPEG [1]:

    local lpeg = require "lpeg"

    local balance = lpeg.Cmt(
      lpeg.P {
        (
          (lpeg.P(1) - lpeg.S"()[]{}<>")
          + lpeg.P"(" * lpeg.V(1) * lpeg.P")"
          + lpeg.P"{" * lpeg.V(1) * lpeg.P"}"
          + lpeg.P"[" * lpeg.V(1) * lpeg.P"]"
          + lpeg.P"<" * lpeg.V(1) * lpeg.P">"
        )^0
      },
      function(subject,position,capture)
        return position,position > #subject
      end
    )

    print(balance:match "")       -- true
    print(balance:match "()")     -- true
    print(balance:match "((()))") -- true
    print(balance:match "()()()") -- true
    print(balance:match "()(())") -- true
    print(balance:match "(")      -- false
    print(balance:match "(()")    -- false
    print(balance:match "({)}")   -- false
    print(balance:match "({})")   -- true
    print(balance:match "()))((") -- false
[1] http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html

There are no comments on this comment yet.