Prolog - generate correct bracketing

Posted by Henrik Bak on Stack Overflow See other posts from Stack Overflow or by Henrik Bak
Published on 2012-05-30T19:37:17Z Indexed on 2012/05/31 22:40 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

I'd like to get some help in the following exam problem, i have no idea how to do this:

Input: a list of numbers, eg.: [1,2,3,4] Output: every possible correct bracketing. Eg.: (in case of input [1,2,3,4]):

((1 2) (3 4))
((1 (2 3)) 4)
(1 ((2 3) 4))
(1 (2 (3 4)))
(((1 2) 3) 4)

Bracketing here is like a method with two arguments, for example multiplication - then the output is the possible multiplication orders.

Please help, i'm stuck with this one. Any help is appreciated, thanks!

© Stack Overflow or respective owner

Related posts about homework

Related posts about list