Reply
Tue 5 Jun, 2012 06:00 am
Suppose you are given (1) a natural number N; (2) a set of natural num-
bers S = {n1; n2; : : : }; (3) a set of arithmetic operators, say +; -;*; =
(with the usual meaning of addition, multiplication, substraction, di-
vision). Your job is to construct an arithmetic expression R built from
the given operators and using each of the numbers in S exactly once,
with R = N.
(a) Explain in general how you could solve that problem.
(b) Solve the speci c instance: N = 24, S = {1; 3; 4; 6}
@mah1,
I've actually done this. You'll need parentheses in the arithmetic expression. You could generate every possible string that looks like n.n.n.n, where . is any operator, but for each of those you 'd have to generate all possible parenthetical groupings. Per a suggestion from someone in another forum, I generated all of the possible postfix representations and wrote a postfix evaluator.
A postfix solution to part b is:
6 1 3 4 / - /