Tcl, 192212 characters.
Unfortunately I can not post my solution directly, because I contains some unicode characters. So here is my utf-8 and base64 encoded solution:
ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOWFlearreODg++wjOqen+iGuOyk
meqOoO+8n+qzmuGBu+iPh+uqkOSendOq4beH6oyD6b236Z2k64WC6ZaJ55KT6Zm344On76CN5I6F5rGa
57uE5JW/5I6i54qE77KV7qCH4reR56iR5J6Z4qCn6LWn7Jqp472r56Gj6pag4ZOL6JiK5rmP66KI6bGw
6JK674qO5KGO4L6a5ayj4aqi6ryN4rSa67KO6Ima7ria47a87YGU47GF6bqT5YKn4baY7LOW5bKg6oe7
7YeH5K+66Ju84Leq4b6c4p2C4aCX56e777q25LGU7Je765iG6K+W6pmn6oim5bGq6Jim452W4Z2O77Sd
5I+Q6ae66Z6c5JOy7qai5KOO5aiv4Le66aGh55G85pu+4puB75C64qmk5pqq6ayZ7KmY6Kal5Za87aKO
4YKC5ayy6qu67b+f7JKa7L6f4pKG6bGU5aOM5p2X5q6w7YKe6Iy27p+H5bWK5LSq6qWB7qWI4r2g5r+2
7LyW642845iV5ouY4puH64GT4Zux45C87aSn56KA6qOf56ad5oKV6KGr54CH6L645bmH6ayr55697qGs
7b6Q5LW447+VXV0=
First decode the base64, then decode utf-8.
It should become something like this:
eval [zlib i [encoding convertt unicode ...some strange characters...]]兕櫭ッﰌꞟ膸줙ꎠ?곚ၻ菇몐䞝Ӫ᷇ꌃ齷靤녂閉璓陷ョ䎅汚组䕿䎢犄ﲕⷑ稑䞙⠧赧용㽫硣ꖠᓋ蘊湏뢈鱰蒺䡎ྚ嬣᪢꼍ⴚ벎艚㶼큔㱅麓傧ᶘ쳖岠ꇻ퇇䯺蛼෪ᾜ❂᠗移ﺶ䱔엻똆诖ꙧꈦ屪蘦㝖ᝎﴝ䏐駺鞜䓲䣎娯顡瑼曾⛁⩤暪鬙쩘覥喼\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
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}
ItWhich 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 <<
<<>> <><>