for question 2. it seems awful but;

Since there are no paranthesis and   "/","*" preceeds "+","-" if there
is an * or / , the leftmost one should be performed before the others.
First check the case if no *,/ occurs by checking all the sums
n1,n2,n3,n4; -n1,n2,n3,n4 ....  (there are 2^4, either negative or
positive, since summation is commutative order doesnt matter) if one
of them equals to 24 then we return true and we are done. Then for
each n1*n2, n1*n3...  make a recursive call for the 3 remaining
numbers (replacing two multiplied original numbers with the result,
for example n1*n2 replacing n1 and n2; so the recursive call is for
n1*n2, n3, n4) there are 6 pairs like that (12 more when "/" is
checked as its not commutative). Execute the same algorithm for 3
numbers and for 2 numbers, when there is only one number left, if it
is not 24 return false, if it is 24 return true.

I guess the brute force approach requires 4!*4^4, this seems to narrow
the search space by exploiting the precedance and commutative rule of
summation and multiplication.


On Oct 2, 4:00 pm, bittu <shashank7andr...@gmail.com> wrote:
> If-a-person-dials-a-sequence-of-numbers-on-the-telephone-what-possible-
> words-strings-can-be-formed-from-the-letters
>
> We are given 4 numbers say n1, n2, n3, n4. We can place them in any
> order and we can use mathematical operator +, -, *, / in between them
> to have final result as 24. Write an algorithm for this, it will take
> 4 numbers and return false or true whether final result 24 is possible
> with any combination.
>
> Pretend there is a robot that has to navigate a maze (N x M). The
> robot can only move down or right and the maze can contain walls.
> Write an algorithm to determine the number of paths the robot can
> take.
>
> If a person dials a sequence of numbers on the telephone, what
> possible words/strings can be formed from the letters associated with
> those numbers?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to