Jump to content

Help with a counting principle problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
pablo25

pablo25

    Newbie

  • Members
  • Pip
  • 2 posts
Hi I was wondering if someone could take a look at this. I am currently doing a project on horse racing and I am
stuck on a piece of programming logic. The piece I am stuck on is based on the counting principle.
I have been trying to find a way to output all the possible permutations ( without Replacement) from a varying
number of inputs

Example 1 :
HorseA
HorseB .
............................

HorseA
HorseB ....is one and only permutation ( a 2 X 1 matrix)



Example 2 :
HorseA Horse C
HorseB EMPTY
..................................

HorseA
HorseB

and

HorseC
HorseB ..... are the permutations (2X2 matrix)





Example 3 :

HorseA HorseC
HorseB HorseD
............................................
HorseA
HorseB

and

HorseC
HorseB

and

HorseA
HorseD

and

HorseC
HorseD

.........are the permutations (2X2 matrix)







I have been trying with for loops. But it is more difficult than it seems. I need the loops top output all
permutations. THE FIRST COLUMN IN THE MATRICES MUST ALWAYS BE FULL -- NOT THE CASE HOWEVER FOR THE OTHER COLUMNS

#2
amischiefr

amischiefr

    Newbie

  • Members
  • Pip
  • 9 posts
Can you be a little more specific about the problem? How many horses are there total? Is the number of horses random/input? So for 3 horses you want something like this:

A

A
B

B
A

A C
B

B C
A

C A
B

C B
A

?????

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It looks like you are actually looking for Combinations, not permutations. I would store your data in a 1xn array (n>=2) and use a nested for loop to go through your data.

for (i=0;i<size-1;i++)
  for (j=i+1;j<size;j++)
    system.out.print(array[i] + " " + array[j]);

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog