Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Algorithm to create possibility of a number ?? it's possible??
Author Message
Manqueba

Posted: Tue May 16, 2017 8:10 pm   Post subject: Algorithm to create possibility of a number ?? it's possible??

I need help building an algorithm.
This algorithm needs to fill a "database", which
Creates all the possibilities of a set of numbers.
For example: 4
4! -> 4 * 3 * 2 * 1 = 24

1234 2134 3124 4123
1243 2143 3142 4132
1324 2314 3214 4213
1342 2341 3241 4231
1423 2413 3412 4312
1432 2431 3421 4321

Is it possible to create this algorithm and work for the other numbers ??
Sponsor
Sponsor

Insectoid

Posted: Wed May 17, 2017 6:38 pm   Post subject: RE:Algorithm to create possibility of a number ?? it\'s possible??

Yes, it's possible. What have you tried? Where are you getting stuck?
Manqueba

Posted: Wed May 17, 2017 7:22 pm   Post subject: RE:Algorithm to create possibility of a number ?? it\'s possible??

I tried to use random numbers, it did not work. I want to populate a matrix with the figures separately. In the example I put in the question I can note that each number repeats in proportion to the value of the factorial number divided by the size of the sequence.
Insectoid

Posted: Sun May 21, 2017 1:42 pm   Post subject: RE:Algorithm to create possibility of a number ?? it\'s possible??

You don't want random numbers, you want a specific pattern of numbers. A specific pattern is a far cry from a random pattern, so why on earth would you think random numbers would work?

How do you plan on storing your matrix of numbers? Well, it looks like for an input of N, you have N! groups of numbers. Each group of numbers is of size N. It makes sense then to store it in a 2-dimensional array of size [N!][N]. In order to populate this array, you need to iterate over every cell. The easiest way to iterate over every cell in a multi-directional array is with nested loops. The outer loop iterates from 0 to N!-1 while the inner loop iterates from 0 to N-1.

Once you have set this up, the actual act of populating the array will hopefully be obvious as that is what this assignment is trying to teach you.
Manqueba

Posted: Sun May 21, 2017 6:23 pm   Post subject: Re: Algorithm to create possibility of a number ?? it's possible??

I have tried to traverse the matrix in this way, but I have not been able to understand how to fill it in such a way that neither possibility is equal to another.
Insectoid

Posted: Sun May 21, 2017 6:24 pm   Post subject: RE:Algorithm to create possibility of a number ?? it\'s possible??

What happens if you simply output the for loop variables?

Edit: Oops, I'm giving bad advice. It's a wee bit more complicated than I let on. My method will work, with some extra effort. The are more efficient though more complicated solutions available. What you're trying to do is generate all permutations of a set. Googling that will give you a number of different algorithms to achieve that.
Manqueba

Posted: Sun May 21, 2017 6:57 pm   Post subject: Re: Algorithm to create possibility of a number ?? it's possible??

Thanks for the advice. I think I'm almost done.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: