thanks don , i got it , it was due the condition in if expression .
modified code
i have highlighted the change

public class Main {


    public static void main(String[] args)
    {
       int digit[]={3,2,5,1};
       for(int num=1;num<=9;num++)
        findNumber(digit,4,num,0,num);
    }

    public static void findNumber(int digit[],int n,int num,int i,int
oldDigit)
    {
        if(i==n)
        {
            System.out.print(num+"  ");
            return;
        }

        {
            int o=digit[i]+oldDigit;
            if(o<10)
                findNumber(digit,n,10*num+o,i+1,o);
            o=oldDigit-digit[i];
            if(o>=0)
 // change done
                findNumber(digit,n,10*num+o,i+1,o);

        }
    }

}

output is
14612  14610  14278  14276  25723  25721  25389  25387  36834  36832  36498
 30278  30276  47945  47943  47501  41389  41387  58612  58610  52498
 52056  52054  69723  69721  63501  63167  63165  74612  74610  74278
 74276  85723  85721  85389  85387  96834  96832  96498
BUILD SUCCESSFUL (total time: 1 second)


now it's ok DON

On Wed, Dec 14, 2011 at 12:50 AM, Don <[email protected]> wrote:

> There should be 39 combinations with that input. You are missing
> numbers which include the digit zero, such as 14610, 30278, and 52056.
>
> Don
>
> On Dec 13, 11:37 am, tech coder <[email protected]> wrote:
> > I tried the problem and written the code for it . it is in java. it is
> > printing all the possible numbers
> > I  am treating the differences ans an array of integers.
> >
> > here is the code
> >
> > public class Main {
> >
> >     public static void main(String[] args)
> >     {
> >        int digit[]={3,2,5,1};// array of absolute differences
> >
> >             int digit[]={3,2,5,1};
> >            for(int num=1;num<=9;num++) // call with all possible initial
> > numbers
> >            findNumber(digit,4,num,0,num);
> >     }
> >
> >     public static void findNumber(int digit[],int n,int num,int i,int
> > oldDigit)
> >     {
> >         if(i==n)
> >         {
> >             System.out.print(num+"  ");
> >             return;
> >         }
> >
> >         {
> >             int o=digit[i]+oldDigit;
> >             if(o<10)
> >                 findNumber(digit,n,10*num+o,i+1,o);
> >             o=oldDigit-digit[i];
> >             if(o>0)
> >                 findNumber(digit,n,10*num+o,i+1,o);
> >
> >         }
> >     }
> >
> > }
> >
> > and here is the output
> >
> > 14612  14278  14276  25723  25721  25389  25387  36834  36832  36498
>  47945
> >  47943  41389  41387  58612  52498  69723  69721  63167  63165  74612
> >  74278  74276  85723  85721  85389  85387  96834  96832  96498
> > BUILD SUCCESSFUL (total time: 0 seconds)
> >
> >
> >
> > On Tue, Dec 13, 2011 at 11:11 PM, Dave <[email protected]> wrote:
> > > @Amir: Presumably, since these are digits in a number, they are
> > > bounded on the bottom by 0 and on the top by radix-1. So in decimal,
> > > if a digit is 7 and the absolute difference between it and the next
> > > digit is 3, there is only one possibility for the next digit, 7-3 = 4,
> > > since 7+3 is too large. So only some subset of the 2^(n-1)
> > > combinations of addition and subtraction may be possible.
> >
> > > Dave
> >
> > > On Dec 13, 4:15 am, Amir hossein Shahriari
> > > <[email protected]> wrote:
> > > > actually there are infinite number of sequences that match it
> > > > for example if the absolute differences are 3 2 5 1
> > > > one possible sequence is 6 3 5 0 1 one other is 7 4 6 1 2 or 8 5 7 2
> 3
> > > > and you can add any integer value to all elements and the result will
> > > still
> > > > be valid
> > > > actually you can start with any number and and then the second number
> > > will
> > > > be equal to the first number that you chose plus/minus the first
> absolute
> > > > difference and so on
> >
> > > > so if we are given the first element of the sequence there are
> 2^(n-1)
> > > ways
> > > > to find a valid sequence because for each absolute difference we can
> > > either
> > > > add the absolute difference to the last sequence element or subtract
> the
> > > > absolute difference from it
> >
> > > > On Mon, Dec 12, 2011 at 9:01 PM, KAY <[email protected]>
> > > wrote:
> > > > > If for a number n digits long, the absolute difference between
> > > > > adjacent digits is given, how to find out the number of different
> > > > > numbers with these absolute differences ?
> >
> > > > > for eg,
> > > > > if n=5
> > > > > and the absolute differences are
> > > > > 3 2 5 1
> > > > > then 1 possible number is
> > > > > 6 3 5 0 1    (because |6-3|=3,|3-5|=2 and so on...)
> >
> > > > > How many such numbers will be there?
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Algorithm Geeks" 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 this group at
> > > > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" 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 this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > *
> >
> >  Regards*
> > *"The Coder"*
> >
> > *"Life is a Game. The more u play, the more u win, the more u win , the
> > more successfully u play"*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" 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 this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*

 Regards*
*"The Coder"*

*"Life is a Game. The more u play, the more u win, the more u win , the
more successfully u play"*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" 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 this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to