Skip to main content
Fixed invalid unicode codepoints
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

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 <<
<<>> <><>

Tcl, 192 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...]]

You count characters, so I use 1 character for 2 bytes.
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}

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 <<
<<>> <><>

Tcl, 212 characters.

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

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 <<
<<>> <><>
added 20 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

Tcl, 191192 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:

ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearneODg+iUjO+Pr+aclOSp
oO6gsuy/qOmrneC9teejouWIkO+Ot+m1iOujoOaBo+67tO6yk+KhkuuEtumYuOu6juePiNqY7Iu85JShZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOWFlearreODg++wjOqen+iGuOyk
5Zyo45it5ICi5rqP7YKJ47OL5YS67KKR5qqY75q86Jiz76qH57u+4bSV5KmJ47mY4oa57Iui7qmx46iSmeqOoO+8n+qzmuGBu+iPh+uqkOSendOq4beH6oyD6b236Z2k64WC6ZaJ55KT6Zm344On76CN5I6F5rGa
46+K5qSh6LC+6KWs45Gq5qq846K05quy5qiJ76645YO26Z2B7aem47O07oqF64Os3aHtq6XjtI57uE5JW/tmo7u5I6i54qE77KV7qCH4reR56iR5J6Z4qCn6LWn7Jqp472r56Gj6pag4ZOL6JiK5rmP66KI6bGw
iZ/lkLfuga/hg7zqhLrvrJ7rmbnlk77vtqDNou+Wo+yzguSTlui1lOyTi++rku2fhui+pe+Rvu+pg+my6JK674qO5KGO4L6a5ayj4aqi6ryN4rSa67KO6Ima7ria47a87YGU47GF6bqT5YKn4baY7LOW5bKg6oe7
me+Sl+2JhOm3k+W6ke2StOyIm++ksO+zqOiLjeOooeaTtOqoqumlpuKCle2Tpe25hOScquKCjO6yhuu67YeH5K+66Ju84Leq4b6c4p2C4aCX56e777q25LGU7Je765iG6K+W6pmn6oim5bGq6Jim452W4Z2O77Sd
luufquKbl+6fseKGs+GUieaZn+qure2is+S8temtqu6PheqZs+mkruqipuWplOaDqe+Yr+GZr++5puOW5I+Q6ae66Z6c5JOy7qai5KOO5aiv4Le66aGh55G85pu+4puB75C64qmk5pqq6ayZ7KmY6Kal5Za87aKO
s+2ituy9oeKmkOejmOG4i+K+muSAmeufmOa9quKtlueaieeihuicguezu+unpO60suaSveidi+yjvO+o4YKC5ayy6qu67b+f7JKa7L6f4pKG6bGU5aOM5p2X5q6w7YKe6Iy27p+H5bWK5LSq6qWB7qWI4r2g5r+2
m+Coh11d7LyW642845iV5ouY4puH64GT4Zux45C87aSn56KA6qOf56ad5oKV6KGr54CH6L645bmH6ayr55697qGs
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...]]

You count characters, so I use 1 character for 2 bytes.
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 {tset ::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$1$3]&[t $2]}]}};append ::m $i} {return 1};list 0}

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 <<
<<>> <><>

Tcl, 191 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:

ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearneODg+iUjO+Pr+aclOSp
oO6gsuy/qOmrneC9teejouWIkO+Ot+m1iOujoOaBo+67tO6yk+KhkuuEtumYuOu6juePiNqY7Iu85JSh
5Zyo45it5ICi5rqP7YKJ47OL5YS67KKR5qqY75q86Jiz76qH57u+4bSV5KmJ47mY4oa57Iui7qmx46iS
46+K5qSh6LC+6KWs45Gq5qq846K05quy5qiJ76645YO26Z2B7aem47O07oqF64Os3aHtq6XjtI/tmo7u
iZ/lkLfuga/hg7zqhLrvrJ7rmbnlk77vtqDNou+Wo+yzguSTlui1lOyTi++rku2fhui+pe+Rvu+pg+my
me+Sl+2JhOm3k+W6ke2StOyIm++ksO+zqOiLjeOooeaTtOqoqumlpuKCle2Tpe25hOScquKCjO6yhuu6
luufquKbl+6fseKGs+GUieaZn+qure2is+S8temtqu6PheqZs+mkruqipuWplOaDqe+Yr+GZr++5puOW
s+2ituy9oeKmkOejmOG4i+K+muSAmeufmOa9quKtlueaieeihuicguezu+unpO60suaSveidi+yjvO+o
m+Coh11d

First decode the base64, then decode utf-8.

It should become something like this:

eval [zlib i [encoding convertt unicode ...some strange characters...]]

You count characters, so I use 1 character for 2 bytes.
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 {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}

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 <<
<<>> <><>

Tcl, 192 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...]]

You count characters, so I use 1 character for 2 bytes.
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}

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 <<
<<>> <><>
added 828 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

Tcl, 187191 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:

ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearr+KDg+yUlO6ev+y4qeSpZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearneODg+iUjO+Pr+aclOSp
gO2gsum/qOatr+O3lueGiOWIkOOnm+KNkui7hu2yge29t+qaveGQq+ukpeq8nO+zp+GDlMan54CoO6gsuy/4KeIqOmrneC9teejouWIkO+Ot+m1iOujoOaBo+67tO6yk+KhkuuEtumYuOu6juePiNqY7Iu85JSh
5ZeK5Laz7YKI6a6j75CT5Jic4qin4aSy6LWT47qX66Gg5r6r4Z2v6YeR4K2l5J+L4pC366ac5beO5J2G5Zyo45it5ICi5rqP7YKJ47OL5YS67KKR5qqY75q86Jiz76qH57u+4bSV5KmJ47mY4oa57Iui7qmx46iS
5pml7LWk4oy46+K5qSh6LC+6KWs45Gq5qq846K05quy5qiJ76645YO26Z2B7aem47O07oqF64Os3aHtq6XjtI/6qmT4LSa4aqP4Lit5ai84aqC67mu5ZC95K+U44W45LS954Wx5aG26I6z7rWy4bq77q2Htmo7u
7qeP6qiL54C36KG+5YKd57aP7ZiI4Zyf472o7KOb67Wo64yw4YS166+956+r74iK7pO345K86Yml55ykiZ/lkLfuga/hg7zqhLrvrJ7rmbnlk77vtqDNou+Wo+yzguSTlui1lOyTi++rku2fhui+pe+Rvu+pg+my
57mC64uS4YOL7KaG7pyn4Zqv7bSc6p6h6qqK4Zyg4bCk446l656T4YeK6Kun6ayf7L+l75e67Ka576e8me+Sl+2JhOm3k+W6ke2StOyIm++ksO+zqOiLjeOooeaTtOqoqumlpuKCle2Tpe25hOScquKCjO6yhuu6
5KGo7JWK5JaL7qur55ii6I+N4Zua74Ox6qeY5LqX6qKz5JK05qOp75uP4KC34byy16fmsJvmjrHhs4brluufquKbl+6fseKGs+GUieaZn+qure2is+S8temtqu6PheqZs+mkruqipuWplOaDqe+Yr+GZr++5puOW
qa3gvYbor43igIzhr6jjjrXplqvlrZTnsYPvt6zli63ot6TutIrsra3vmobml6Xlk5fHvV1ds+2ituy9oeKmkOejmOG4i+K+muSAmeufmOa9quKtlueaieeihuicguezu+unpO60suaSveidi+yjvO+o
m+Coh11d

First decode the base64, then decode utf-8.

It should become something like this:

eval [zlib i [encoding convertt unicode ...some strange characters...]]

You count characters, so I use 1 character for 2 bytes.
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 {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}

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 <<
<<>> <><>

Tcl, 187 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:

ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearr+KDg+yUlO6ev+y4qeSp
gO2gsum/qOatr+O3lueGiOWIkOOnm+KNkui7hu2yge29t+qaveGQq+ukpeq8nO+zp+GDlMan54C/4KeI
5ZeK5Laz7YKI6a6j75CT5Jic4qin4aSy6LWT47qX66Gg5r6r4Z2v6YeR4K2l5J+L4pC366ac5beO5J2G
5pml7LWk4oy/6qmT4LSa4aqP4Lit5ai84aqC67mu5ZC95K+U44W45LS954Wx5aG26I6z7rWy4bq77q2H
7qeP6qiL54C36KG+5YKd57aP7ZiI4Zyf472o7KOb67Wo64yw4YS166+956+r74iK7pO345K86Yml55yk
57mC64uS4YOL7KaG7pyn4Zqv7bSc6p6h6qqK4Zyg4bCk446l656T4YeK6Kun6ayf7L+l75e67Ka576e8
5KGo7JWK5JaL7qur55ii6I+N4Zua74Ox6qeY5LqX6qKz5JK05qOp75uP4KC34byy16fmsJvmjrHhs4br
qa3gvYbor43igIzhr6jjjrXplqvlrZTnsYPvt6zli63ot6TutIrsra3vmobml6Xlk5fHvV1d

First decode the base64, then decode utf-8.

You count characters, so I use 1 character for 2 bytes.
The zlib is pretty self explanatory. i is just the the abbreviation of inflate.
eval. Well. I don't have to explain that?

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 permutation. They have all the same length.

Tcl, 191 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:

ZXZhbCBbemxpYiBpIFtlbmNvZGluZyBjb252ZXJ0dCB1bmljb2RlIOmFlearneODg+iUjO+Pr+aclOSp
oO6gsuy/qOmrneC9teejouWIkO+Ot+m1iOujoOaBo+67tO6yk+KhkuuEtumYuOu6juePiNqY7Iu85JSh
5Zyo45it5ICi5rqP7YKJ47OL5YS67KKR5qqY75q86Jiz76qH57u+4bSV5KmJ47mY4oa57Iui7qmx46iS
46+K5qSh6LC+6KWs45Gq5qq846K05quy5qiJ76645YO26Z2B7aem47O07oqF64Os3aHtq6XjtI/tmo7u
iZ/lkLfuga/hg7zqhLrvrJ7rmbnlk77vtqDNou+Wo+yzguSTlui1lOyTi++rku2fhui+pe+Rvu+pg+my
me+Sl+2JhOm3k+W6ke2StOyIm++ksO+zqOiLjeOooeaTtOqoqumlpuKCle2Tpe25hOScquKCjO6yhuu6
luufquKbl+6fseKGs+GUieaZn+qure2is+S8temtqu6PheqZs+mkruqipuWplOaDqe+Yr+GZr++5puOW
s+2ituy9oeKmkOejmOG4i+K+muSAmeufmOa9quKtlueaieeihuicguezu+unpO60suaSveidi+yjvO+o
m+Coh11d

First decode the base64, then decode utf-8.

It should become something like this:

eval [zlib i [encoding convertt unicode ...some strange characters...]]

You count characters, so I use 1 character for 2 bytes.
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 {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}

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 <<
<<>> <><>
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44
Loading