On Nov 19, 2007 10:59 AM, Dan Bron <[EMAIL PROTECTED]> wrote:
> Provide a monad that provides every possible parenthesization of the words of
> its argument.
> In addition to the standard brevity/elegance/speed metrics, bonus points will
> be awarded for
> elision of superfluous parens, ordering results by number of parens, and
> tacit solutions.
What are "superfluous" parens, in this context?
For example, should we be assuming some particular kind of word?
For example, does this qualify?
paren1=: <@('(' , ')',~ ;:inv) [EMAIL PROTECTED](1 = [EMAIL PROTECTED])
parens=: (2 +/\"[EMAIL PROTECTED]:@[EMAIL PROTECTED] #) paren1/.^:(1 < [EMAIL
PROTECTED]@[)"1 ]
parenthesis=: [: ;:inv"1 ([: ~.@; <@[EMAIL PROTECTED]&a:"1)^:_@,:@;:
parenthesis 'a b c d'
a b c d
(a b c) d
(a b) (c d)
(a b) c d
a (b c d)
a (b c) d
a b (c d)
((a b) c) d
(a (b c)) d
a ((b c) d)
a (b (c d))
I probably should have used boxes rather than a flat list, when grouping
my candidate sentences (this would have let me get rid of the -.&a:) but I
am not sure if this is a big enough issue to worry about, and thought I
should get clarification as well.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm