## All Correct!

*February 13, 2009 at 10:57 am* *narinderberi* *
Leave a comment *

Write a function:

void printAllCorrect(char* expr);

which displays all possible ‘parenthesizing’s of expr which evaluate to Correct, where expr is of form:

Correct And Wrong Or Correct Xor Wrong

So, in this example we have 2 operands Correct and Wrong and there are 3 operators: And, Or, Xor. In general there can be n operands each of which shall be either Correct or Wrong, and m operators each of which shall be either of And, Or, Xor.

One possible solution is for the given example is:

(Correct And ((Wrong Or Correct) Xor Wrong))

What is the complexity of your solution?

Advertisements

Entry filed under: Puzzles.

Trackback this post | Subscribe to the comments via RSS Feed