BUILD GATES
Make do without an OR gate
Your cousin Bill has a patented process that produces AND and NOT circuits
very efficiently. Unfortunately, OR logic is very expensive. He offers
to wash your laundry for the next year if you can fix the problem.
INPUT: gates.in
A sequence of logical expressions, one per line, which conform to the
following grammar:
E := '!' E | '(' E '&'
E
')' | '(' E '|' E ')' | V
V := 'a' | 'b' | ... | 'z'
Here the bold are nonterminals or parts of the BNF grammar,
while the 'teletype' are terminals. Of course '!' is unary NOT,
'&' is binary AND, and '|' is binary OR.
Other than end-of-line terminators marking the end of each expression,
there will be no white space in the input file. Here's an example:
x
(x&!(y|!z))
!(x|y)
OUTPUT: gates.out
For each expression in the input, you are to produce an equivalent
expression in the output, i.e., one that gives the same truth value for
all possible combinations of the input, but without using the '|' OR operation.
The generated expression must conform to the same grammar, with the
same white space restrictions. A correct output for the example input would
be:
x
(x&(!y&z))
(!x&!y)