Interlocking Brackets Write a program or function that takes in an eight byte string containing one of each of the characters ()[]{}&lt;&gt; arranged in any way such that the four respective bracket types match. For example, ]&lt;([){}&gt; is invalid input because the square brackets don't match (though all the others do).

Print or return an integer from 0 to 6 that denotes how many of the six possible pairings of the four bracket types are interlocked. Bracket type pairs are considered interlocked if exactly one bracket of one type occurs between the brackets of the other type. So ([)] and [(]) are interlocked but ()[], [](), ([]), and [()] are not.

The shortest code in bytes wins.

Input/Output Examples

()[]{}&lt;&gt; : 0
([{&lt;&gt;}]) : 0
&lt;&gt;{[]}() : 0
{&lt;&gt;([])} : 0
&lt;(&gt;)[{}] : 1
&lt;[({)}]&gt; : 1
[{&lt;}]&gt;() : 2
{&lt;&gt;([}]) : 2
&lt;{(&gt;})[] : 3
[(]&lt;){&gt;} : 3
&lt;([&gt;{)}] : 4
(&lt;{[&gt;})] : 4
(&lt;[{)&gt;}] : 5
&lt;{[(&gt;})] : 5
[{&lt;(]}&gt;) : 6
(&lt;{[)&gt;}] : 6
CJam, 18

l7~f&amp;_f{\/~;&amp;}s,2/


Thanks isaacg for some golfing ideas :)
Try it online or try all examples

Explanation:

l         read a line of input
7~f&amp;      clear the lowest 3 bits of each character
           the goal is to convert brackets of the same type to the same char
_         duplicate the resulting string, let's call it S
f{…}      for each character in S, and S (the char and S are pushed every time)
  \       swap the character with S
  /       split S around that character, resulting in 3 pieces:
           before, between, after
  ~       dump the pieces on the stack
  ;       pop the last piece
  &amp;       intersect the first 2 pieces
          after the loop, we have an array of strings
          containing the chars interlocking to the left with each char of S
s         join all the string into one string
,         get the string length
2/        divide by 2, because S has duplicated characters