Home arrow static arrow Java Programming [Archive] - Permutation
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Permutation
This topic has 36 replies on 3 pages.    « Previous | 1 | 2 | 3 | Next »

Posts:357
Registered: 8/5/04
Re: Permutation  
Aug 8, 2004 5:32 PM (reply 15 of 36)



 
Below is the class it works Perfectly only thing is that i don't understand those two statements function.
there is no array.reset() required here

just a little explanation of below two lines please..

thanks a lot

import java.util.Random; /**   This class provides a method to generate permutations.*/public class PermutationGenerator{   /**      Construct a PermutationGenerator object   */   public PermutationGenerator()   {      generator = new Random();   }    /**      Gets the next permutation      @param n the maximum number in the permutation      @param r the array containing the permutations   */   public int[] nextPermutation(int n)   {        int[] p = new int[n];      for (int i = 0; i < n; i++)          p[i] = i + 1;               int pSize = n;      int[] r = new int[n];            for (int i = 0; i < n; i++)      {  int pos = generator.nextInt(pSize);         r[i] = p[pos];         p[pos] = p[pSize - 1];//this         pSize--;//this       }      return r;   }      private Random generator;}
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:32 PM (reply 16 of 36)



 
And i was having fun yaw.
You went and spoiled it :)
/k1

I didn't spoil it. There's also the Arrays.permutate() method in the javadocs that PERFECTLY describe what those two statements are for.
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:34 PM (reply 17 of 36)



 
just a little explanation of below two lines please..

Oh! I was confused about what you wanted. The explanation of those two lines is as follows: they set the value of p[pos] to the value of p[pSize - 1], then decrement the pSize variable each time by one.
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:35 PM (reply 18 of 36)



 
I still say that A should look up Arraya.reset() in the javadoc.
Might be an education
/k1
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:40 PM (reply 19 of 36)



 
I still say that A should look up Arraya.reset() in
the javadoc.
Might be an education
/k1

I agree, but there's NO TIME! The Symbionese Liberation Army is about to chase Annie over the edge of a cliff, and she's gotta permute NOW!
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:42 PM (reply 20 of 36)



 
OMG i really didn't think it was all that urgent.
I should reform my ways.
/k1
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:44 PM (reply 21 of 36)



 
btw I can't find Arraya.reset() in the javadoc.... am I doing something wrong?
/k1
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:44 PM (reply 22 of 36)



 
OMG i really didn't think it was all that urgent.

Hey, when Annie says it's urgent, she means it's URGENT.
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:45 PM (reply 23 of 36)



 
btw I can't find Arraya.reset() in the javadoc.... am
I doing something wrong?
/k1

Maybe check under Arrayb.reset(), esp. if you're using Tiger.
 

Posts:357
Registered: 8/5/04
Re: Permutation  
Aug 8, 2004 5:46 PM (reply 24 of 36)



 
i don't have api documentation at hand.
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:47 PM (reply 25 of 36)



 
What's tiger? Does it solve the OP?
 

Posts:24,036
Registered: 2/3/03
Re: Permutation  
Aug 8, 2004 5:48 PM (reply 26 of 36)



 
What's tiger? Does it solve the OP?

Most likely. Tiger handles a lot of things like autopackaging, genetics, and entuperations.
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:48 PM (reply 27 of 36)



 
counting down the supposed hours to A's "exam"
use them wisely :)
 

Posts:826
Registered: 7/1/03
Re: Permutation  
Aug 8, 2004 5:50 PM (reply 28 of 36)



 
wow i can think of a good use for that genetics stuff.
where can i get this softwear?
 

Posts:8,813
Registered: 10/4/00
Re: Permutation  
Aug 8, 2004 5:54 PM (reply 29 of 36)



 
What's tiger? Does it solve the OP?

Most likely. Tiger handles a lot of things like
autopackaging, genetics, and entuperations.

All this time I've been manually entuperating. What wil they think of next?
 
This topic has 36 replies on 3 pages.    « Previous | 1 | 2 | 3 | Next »