Hi ,

I think we can do a very generic solution by

dividing the target in three cases
1) Target is smaller than all the 6 integer
2) Target is in between the 6 integers
3) Target is greater than all 6 integers

solving case 1) search if any given integer is multiple of the target else
try to get to the no. by allowed arithmetic operations (can also be done
recursively by keeping base case where we reach the the target itself else
iterate)

solving case 2)   now again search for the fact if any no or target is
multiple of any of the no  else try to get to the no. by allowed arithmetic
operations (can also be done recursively by keeping base case where we
reach the the target itself else iterate)
eg if target is 20 and integers are 1 5 7 9 11 23
then 20 is multiple of 5
eg2. if target is 7 and integers are 2 13 15 23 31 49
here 49 is multiple of 7

solving case 3) Search for target being multiple of any integer   else try
to get to the no. by allowed arithmetic operations (can also be done
recursively by keeping base case where we reach the the target itself else
iterate)



getting to the target can be common method where it recursively call itself
and tries to get near to the target using given integers. Base case being
we reach to the Target ie return value being the diff=0 or remainder=0

Above being very raw solution. Please suggest if this provides any
meaningful solution to you.


Regards
Ankur

On Thu, Apr 4, 2013 at 5:07 PM, prankur gupta <duke.lnm...@gmail.com> wrote:

> I guess we are allowed to use the operation multiple times.
> I had thought of the solution, could you please look below and tell me
> whether I'm missing any case or not.
> I know the complexity of the solution is very bad(exponential).
> But if you have some other cool algorithm I would be happy to hear.
>
> The only case which I was able to think of was
> 1) Generate all possible permutation of those 6 integers.
> 2) Generate repeated permutation of the 4 operands on 5 places.
> eg. +,+,+,*,/ etc
> 3) Do a Shuffle merge of these two lists (Every permutation of (1) with
> every permutation of (2))
> 4) You get the inorder, convert it to post order and evaluate the
> expression.
>
> Thanks.
>
>
>
> On Thu, Apr 4, 2013 at 2:05 AM, atul anand <atul.87fri...@gmail.com>wrote:
>
>> are we allowed to use operation only once or multilpe times?
>>
>>
>> On Fri, Mar 22, 2013 at 6:27 AM, prankur gupta <duke.lnm...@gmail.com>wrote:
>>
>>> Hi All,
>>>
>>> Could you help me this question.
>>> This was asked at Yelp Interview.
>>>
>>> Given 6 integers and 1 target value, write a function to get the target
>>> value using 6 integers with any on these operations +,*,-,/
>>>
>>> Thanks
>>>
>>> --
>>> PRANKUR GUPTA
>>>
>>> Masters Student (CSE)
>>> State University of New York
>>> Stony Brook University
>>> prgu...@cs.stonybrook.edu
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> PRANKUR GUPTA
>
> Masters Student (CSE)
> State University of New York
> Stony Brook University
> prgu...@cs.stonybrook.edu
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to