Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ()[]{}<> : 0
- ([{<>}]) : 0
- <>{[]}() : 0
- {<>([])} : 0
- <(>)[{}] : 1
- <[({)}]> : 1
- [{<}]>() : 2
- {<>([}]) : 2
- <{(>})[] : 3
- [(]<){>} : 3
- <([>{)}] : 4
- (<{[>})] : 4
- (<[{)>}] : 5
- <{[(>})] : 5
- [{<(]}>) : 6
- (<{[)>}] : 6
- l7~f&_f{/~;&}s,2/
- l read a line of input
- 7~f& 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
- & 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
- y/([{</)]}>/
- s/.*/t& & & & /
- :b
- y/)]}>/]}>)/
- s/S*>(S*)>S* /1t/
- t
- s/S* //
- :
- s/(tS*)(S)(S*)2(S*t)/134/
- t
- s/S *$/&/
- tb
- s/s//g
- s/../1/g
- perl -pe 'y/)]}>/([{</;for$x(/./g){$h{$x="\$x"}++&&s!$x(.*)$x!$z+=length$1,$1!e}$_=$z'
- JmC/CdTzlsm@FPcsJd{J
- (T`)]>}`([<{
- (D)(.*)1(.*)
- n$2n$3
- (?=(D).*n.*1)
- 1
- n
- <empty>
- (T`)]>}`([<{
- (D)(.*)1(.*)
- #$2#$3
- (?=(D)[^#]*#[^#]*1)
- 1
- #
- <empty>
- T`)]>}`([<{
- (D)(.*)1(.*)
- n$2n$3
- (?=(D).*n.*1)
- 1
- n
- <empty>
- x=>(a=b=0,[for(c of x)for(d of'1234')(e=c.charCodeAt()/26|0)==d?a^=1<<d:b^=(a>>d&1)<<d*4+e],f=y=>y&&y%2+f(y>>1))(b)/2
- () => 40,41
- <> => 60,62
- [] => 91,93
- {} => 123,125
- b^=(a>>d&1)<<d*4+e
- f=y=>y&&y%2+f(y>>1)
- f(y) => y && y%2 + f(y>>1)
- f(0b1001101) => 1 + f(0b100110) = 4
- f(0b100110) => 0 + f(0b10011) = 3
- f(0b10011) => 1 + f(0b1001) = 3
- f(0b1001) => 1 + f(0b100) = 2
- f(0b100) => 0 + f(0b10) = 1
- f(0b10) => 0 + f(0b1) = 1
- f(0b1) => 1 + f(0b0) = 1
- f(0b0) => 0 = 0
- WITH v AS(SELECT b,MIN(p)i,MAX(p)a FROM(SELECT SUBSTR(TRANSLATE(:1,'])>}','[(<{'),LEVEL,1)b,LEVEL p FROM DUAL CONNECT BY LEVEL<9)GROUP BY b)SELECT COUNT(*)FROM v x,v y WHERE x.i<y.i AND x.a<y.a AND y.i<x.a;
- WITH v AS( -- Compute min and max pos for each bracket type
- SELECT b,MIN(p)i,MAX(p)a
- FROM ( -- replace ending brackets by opening brakets and split the string
- SELECT SUBSTR(TRANSLATE(:1,'])>}','[(<{'),LEVEL,1)b,LEVEL p
- FROM DUAL
- CONNECT BY LEVEL<9
- )
- GROUP BY b
- )
- SELECT COUNT(*)
- FROM v x,v y
- WHERE x.i<y.i AND x.a<y.a AND y.i<x.a -- Apply restrictions for interlocking brackets
Add Comment
Please, Sign In to add comment