siteturbo Posted January 28, 2010 Share Posted January 28, 2010 Hello All: I've been trying this for the last 3 or 4 days and haven't figured it out yet. Any help would be appreciated. THE PROBLEM: I am trying to output a sequence or combination numbers, from say, 1 through 5 using only the digits 1 through 5, and all their possible combinations. Example #1: digits 1, 2, 3 The possible combinations are... 1,2,3 1,3,2 2,1,3 2,3,1 3,2,1 3,1,2 Example #2: digits 1, 2, 3, 4 The possible combinations are... 1,2,3,4 1,2,4,3 1,3,2,4 1,3,4,2 1,4,2,3 1,4,3,2 2,1,3,4 2,1,4,3 and so on... HINT... I know that each solution should have n! (n factorial) solutions. In other words, for 3 digits (numbers 1 through 2), there are 3! solutions, or 3x2x1 = 6 solutions. For 4 digits, there are 4! solutions, or 4x3x2x1 = 24 solutions. And so on. I would like to be able to plug in a number, say "X", and get all combinations of all numbers form 1 to "X". I've tried nesting for loops, trying using one for loop with multiple expressions, etc. However, no success. Anyone with a lot of brain power want to give it a shot?! Thanks a bunch! -- Ed Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 28, 2010 Share Posted January 28, 2010 Sounds like homework Quote Link to comment Share on other sites More sharing options...
siteturbo Posted January 28, 2010 Author Share Posted January 28, 2010 Yeah, I almost had it a couple of times, but have not triumphed yet. It's become a puzzle to me. Quote Link to comment Share on other sites More sharing options...
siteturbo Posted January 28, 2010 Author Share Posted January 28, 2010 I found the exact solution to my problem at http://cogo.wordpress.com/2008/01/08/string-permutation-in-php/ Quote Link to comment Share on other sites More sharing options...
GrooN Posted January 28, 2010 Share Posted January 28, 2010 You know theres a formula for this right? a b c d how many different ways can that be show: 1 * 2 * 3 * 4 = 24 24 possible ways to display that. Quote Link to comment Share on other sites More sharing options...
akitchin Posted January 28, 2010 Share Posted January 28, 2010 groon, you didn't at all help - if you read his original post, he points out that he already knows how many permutations can exist for the given series (n!). siteturbo, if this thread is solved, please mark it as such. Quote Link to comment Share on other sites More sharing options...
GrooN Posted January 28, 2010 Share Posted January 28, 2010 Yea, okay sorry. My bad... ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.