As I suggested, represent the concatenation of digits as a fifth operator,
one with highest priority. "X concat Y" simply equals 10X+Y, even more than
two digits are concatenated if you perform the concatenations left to
right, with X not allowed to be 0 (but be careful to allow Y to be 0 in "X
concat Y concat Z").

If you have to keep the digits in their original order (which is how I read
what you've written), then the number of sequences, before eliminating
impossible ones, is simply 5^(D-1) where D is the number of digits. Even at
10 digits this is less than 2 million sequences, so it is reasonable to
attempt a brute force method of finding them. Write a function that takes a
list of digits and a list of operations to put between them. Make one pass
to do the concatenations (rejecting the case on a leading 0), one pass to
do multiplications and divisions (rejecting division by zero), and one pass
to do addition and subtraction. Another routine generates all the possible
sequences of operations in a loop and calls this one for each case.

**


On Thu, Nov 15, 2012 at 10:59 AM, Amir Hossein Sharifzadeh <
[email protected]> wrote:

> Hello,
>
> I will need to find all of the distinct results.But first I should
> represent them.
> Also, operatoions always performed based on priority but not left to right.
>
> I could not implement to code. Therefore, I divide the problem in two
> sections:
> 1. Representing distinct sequences
> 2. Computing sequences with operators
>
> Thanks a lot for if you could help me.
>
>
>
> On Thu, Nov 15, 2012 at 10:47 AM, Joseph DeVincentis <[email protected]>wrote:
>
>> What's the goal? Do you want the number of distinct operation sequences
>> that are valid, or do you want to find all the distinct results? Are the
>> operations always performed left to right, or using order of operations
>> with multiplication and division first?
>>
>> You also need to avoid dividing by zero. (2 / 0 + 1 = wrong)
>>
>> You can model the concatenation of two or more digits into a multi-digit
>> number as a fifth operator.
>>
>>
>>  On Thu, Nov 15, 2012 at 10:36 AM, Amir Hossein Sharifzadeh <
>> [email protected]> wrote:
>>
>>>  Hi,
>>>
>>> Suppose we have a number and some operators(*,-,+,/). We would like to
>>> represent and compute operators along operands during a number.
>>> For example:
>>>
>>> N = 201
>>> Operators: +,-,* and /
>>>
>>> Results should be represented as following down: (I represented just +
>>> and - operators)
>>> 2 + 0 + 1
>>> 2 + 01 (wrong)
>>> 20 + 1
>>>
>>> 2 + 0 - 1
>>> 2 - 01 (wrong)
>>> 20 - 1
>>>
>>> 2 - 0  + 1
>>> 2 - 0  - 1
>>>
>>> We would not change the numbers and should insert operators between
>>> operands and compute the possibility values. (For example 2 + 01 may not be
>>> calculated)
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Google Code Jam" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Google Code Jam" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to