![]() (I got it right to!)(and it was required we do it recursivily) Quote:Originally posted by Fblue:I had to do this on a midterm, on paper for 1234.n. It is its only permutation.See the gist of it?quote:But anyway, this is the formula to calculate the number of permutations: (assuming there are 4 numbers)4 x 3 x 2 x 1 Which is equals to 24.The number of permutations of N items, R of them taken at a time, is N! / (N -R)!.Jeremy Its permutations consist of 2 prepend to all the permutations of 3, and 3 prepended to all the permutations of 2.So consider the string 3. Its permutations consist of 1 prepended to all the permutations of 23, 2 prepended to all the permutations of 13, and 3 prepended to all the permutations of 12.So consider the string 23. ![]() For each digit of the string, its permutations is the number prepended to the set of all other permutations of the remaining digits in the string.So consider the string 123. Many terms here sounds very alien to me.It's not too hard a task just consider it recursively (that is, define in terms of itself). I admits that i didnt perform well for my math all my life. Quote:Originally posted by fusefreak:Sheesh. Instead of just calculating 5*4*3*2*1 and telling you the answer, it is running through the permutationsSwitch the last two items (pattern for two items)Move the next character into each of three places, and repeat the two items test each timeMove the *next* character into each of four places, and repeat the three items test each time. * 2 * 1 = 5040-This is what the code above is doing. Four times the results for Three numbers is: 4x3x2 = 24Which comes out as the factorial function.n! = n * (n-1) * (n-2). The 1 can be in four places, and for each place, the rest of the numbers have the same patterns as for Three numbers. Three times the combinations: 3*2 = 6Permutations of 4 numbers 1 2 3 41 2 4 31 3 2 41 4 2 31 3 4 21 4 3 2. I cant remember.Just doing it for the fun.įusefreakThe pattern is quite nice really Permutations of 1 number 1 (One number)Permutations of 2 numbers 12 (Two, you can only swap them around)21Permutations of 3 numbers 1 2 3 (Compare this with the above: (? a b) and (? b a)1 3 2 2 1 3 (Then (a ? b) and (b ? a)3 1 22 3 1 (Then (a b ?) and (b a ?)3 2 1See the emerging pattern? The 1 can be in three places, and for each place the rest of the pattern is the same as for Two numbers. Then on Wed, Sat, and Sun, at 6pm, you log on to the website to see whether your number matches one of the 23 numbers listed on the site.Btw, I thought there are 12 permutations? Because whether i bought this option, the ticket says 12 permutations? Or was it 24? Sheesh. For your information, this is one of the way of betting over here: you buy 4 numbers, and you have an option to buy all permuations of it - View image here:. I assume you're looking for help as opposed to just an answer?Brian The code to do this is pretty simple, but I'll hold of on posting it. View image here: - First, there are 24 permutations, not 12. Permute(level + 1, permuted + original.Quote:Originally posted by glenthas:This sounds suspiciously like homework. Static void permute(int level, String permuted, Static int k= reader.readInt("Enter k-tuple") Static KeyboardReader reader= new KeyboardReader () Here's the program, the output it's giving me right now, and the output I want it to give me. I've got it working to the point where I can get the permutations, but it only shows the ones with no repeats. The program should ask the user for the value of k, the length of the permutation. I want to create an array of all permutations of a series of 4 letters (Call them A,C,G,T for the 4 types of nucleotide bases).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |