Miggy23@gmail.com
Guest
Posts: n/a

 12-01-2005
Hello everyone,

I apologize for taking up anyone's time with such a newbie question.
However, my daughter is tearing her hair out over this code. I myself
don't know anything about programming however, being the father that I
am, I am hoping that someone can respond to my plea for help and
provide her with a solution. Below is her code. Thank you all and God
Bless!!

Problem: Print out all the 4 number combinations using only the
following numbers: 6, 9,0,3,1

The code is giving her only 5 combinations at the moment. This is
where she needs help.

//Source code//

import java.math.BigInteger;

public class NumGen {
public static void main(String[] args) {
char[] elements = {'6', '9', '0', '3', '1'};
int[] indices;
CombinationGenerator x = new CombinationGenerator (elements.length,
4);
StringBuffer combination;

while (x.hasMore ()) {
combination = new StringBuffer ();
indices = x.getNext ();
for (int i = 0; i < indices.length; i++) {
combination.append (elements[indices[i]]);
}
System.out.println (combination.toString ());
}

}
}

Oliver Wong
Guest
Posts: n/a

 12-01-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Problem: Print out all the 4 number combinations using only the
> following numbers: 6, 9,0,3,1

The problem statement is not clear to me. Is it asking for all strings
of length 4 whose alphabet is {6, 9, 0, 3, 1}? Or is it asking to print all
permutations of the set {6,9,0,3,1}, except don't print the last character?
Or something else?

Here's a legal string from the first interpretation which is not legal
in the second interpretation, in case the difference isn't clear: 0000.

- Oliver

cbroussard@liquiddatainc.com
Guest
Posts: n/a

 12-01-2005
You also did not paste an additional class file CombinationGenerator.
Also what's the purpose this class??

http://www.binaryfrost.com

Daniel Dyer
Guest
Posts: n/a

 12-01-2005
On Thu, 01 Dec 2005 22:25:26 -0000, <(E-Mail Removed)> wrote:

> You also did not paste an additional class file CombinationGenerator.
> Also what's the purpose this class??
>

It's almost certainly this class (or something very similar)

http://www.merriampark.com/comb.htm

I stumbled across it myself a few weeks back when looking for some code to
generate combinations. The algorithm is sound but I modified it to work
with longs rather than BigIntegers since I didn't need to work with big
sets and I used generics to get it actually generate the combinations as
arrays of the appropriate type rather than just an int array of indices.

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk

Miggy23@gmail.com
Guest
Posts: n/a

 12-01-2005
Sorry for the confusion everyone. I am trying my best to be clear.
She is trying to print out all the possible number combinations of
length 4 using only the following numbers: 6,9,0,3, and 1.

Miggy23@gmail.com
Guest
Posts: n/a

 12-01-2005
Daniel,

Thanks for the link, however, how would she modify the code to only do
9,6,3,0,1 instead of alphabets of length 4?

frankgerlach@gmail.com
Guest
Posts: n/a

 12-01-2005
I guess someone is trying to get his homework done by using the usenet
)

Miggy23@gmail.com
Guest
Posts: n/a

 12-01-2005
Thanks for the reply Oliver. Sorry for the confusion. She is trying
to find all strings of length 4 whose alphabet is {6,9,0,3,1). In
other words, find all the possible number combinations for {6,9,0,3,1)
of lenght 4. Sorry if I am still not clear. I'm not a programmer.

Thank you all for your help!!

Oliver Wong
Guest
Posts: n/a

 12-01-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Sorry for the confusion everyone. I am trying my best to be clear.
> She is trying to print out all the possible number combinations of
> length 4 using only the following numbers: 6,9,0,3, and 1.
>

To me, there is no new information in this post with respect to your
original one.

Here's what I understand (and have understood since the first post):

The strings are of length 4.
Using characters other than 6, 9, 0, 3, 1 is not permitted.
You want ALL such strings.

Here's what's unclear (and was unclear since the first post):

Can the characters repeat? E.g. is 0000 a legal string?
Is the fact that the numbers not in any discernable order of some
significance? I.e. why didn't you say "0,1,3,6,9"?
Why is BigInteger getting involved for such small integers?
What is CombinationGenerator? Or more importantly, where did it come
from? You daughter? The teacher? Somewhere else?

- Oliver

Oliver Wong
Guest
Posts: n/a

 12-01-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Thanks for the reply Oliver. Sorry for the confusion. She is trying
> to find all strings of length 4 whose alphabet is {6,9,0,3,1). In
> other words, find all the possible number combinations for {6,9,0,3,1)
> of lenght 4. Sorry if I am still not clear. I'm not a programmer.
>
> Thank you all for your help!!

Does she know what recursion is?

- Oliver