# Tcl, 212 characters. <!-- language: lang-tcl --> eval [zlib i [encoding convertt unicode 兕櫭ッﰌꞟ膸줙ꎠ?곚ၻ菇몐䞝Ӫ᷇ꌃ齷靤녂閉璓陷ョ䎅汚组䕿䎢犄ﲕⷑ稑䞙⠧赧용㽫硣ꖠᓋ蘊湏뢈鱰蒺䡎ྚ嬣᪢꼍ⴚ벎艚㶼큔㱅麓傧ᶘ쳖岠ꇻ퇇䯺蛼෪ᾜ❂᠗移ﺶ䱔엻똆诖ꙧꈦ屪蘦㝖ᝎﴝ䏐駺鞜䓲䣎娯顡瑼曾⛁⩤暪鬙쩘覥喼\ud88eႂ嬲\udfdf쒚쾟⒆鱔壌杗殰킞茶嵊䴪ꥁ⽠濶켖덼㘕拘⛇끓ᛱ㐼\ud927碀禝悕衫瀇辸幇鬫瞽\udf90䵸㿕]] You count characters, so I use 1 character for 2 bytes. (Except the invalid characters, that I replaced now) The zlib is pretty self explanatory. `i` is just the the abbreviation of `inflate`. `eval`. Well. I don't have to explain that? After decoding it becomes <!-- language: lang-tcl --> proc v i {set ::m {};t $i set r [list [split $i {}]] lmap c [split $::m {}] {set c [dict get {\{ \} \} \{ {[} \] \] {[} ( ) ) ( < > > <} $c] lmap a $r[set r {}] {for {set i 0} \$i<=[llength $a] incr\ i {lappend r [linsert $a $i $c]}}} lsort -u [lmap a [lmap a $r {join $a {}}] {if {![t $a]} continue set\ a}] } proc t i {if {{}ne$i} {lmap r {{^(.*){(.*?)}(.*)$} {^(.*)\((.*?)\)(.*)$} {^(.*)<(.*?)>(.*)$} {^(.*)\[(.*?)\](.*)$}} {if {[regexp $r $i - 1 2 3]} {return [expr {[t $1$3]&[t $2]}]}};append ::m $i} {return 1};list 0} Which will be passed to `eval`. It defines 2 commands: `v`, the main program, and `t` which checks the input and place unmatched braces in the global variable `m`. `v` calls `t` with the input, insert the corresponding brace at all possible positions and use `t` again to filter the valid ones out. **Input**: 1. Parameter for `v` **Output**: A Tcl list with each possible valid permutation. They have all the same length. Example: % v << <<>> <><>