Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Looping through all combinations

    Hi. I'm new here and such. It's been a few years since I've been on any coding forums, but this one seems to be the most active from the forums I remember.

    Anyway, I know this has been discussed many times before, but what I'm trying to do is a little different, and I have yet to find or come up with any satisfactory solutions. Basically, given the array, $arr = array(0, 1, 2, 3, 4);, I want to produce the following results:
    Code:
    01234
    0123
    0124
    0134
    0234
    1234
    012
    013
    014
    023
    024
    034
    123
    124
    134
    234
    01
    02
    03
    04
    12
    13
    14
    23
    24
    34
    0
    1
    2
    3
    4
    The order of the elements in the array are from most to least important. In other words, the order of the results are from most to least important, or most to least similar to the original array.
    Right now I can't even think of how to get started, so any help would be greatly appreciated.

    Thanks!
    Last edited by DavidB3ck; 07-17-2012 at 09:18 PM.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,978
    Thanks
    15
    Thanked 230 Times in 230 Posts
    How similar this is to something I am working with/on! This is a problem in combinatorics, to give it a mathematical name. You have 5 distinct items, they can be ordered in 120 ways, you only want them ordered in 20 particular ways, quite interesting.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •