How do I generate a list of possible combinations?

0 favourites
  • 6 posts
From the Asset Store
Over 2700 files with all the colour combinations from a 15 colours palette!
  • Hi I am new to construct and programming in general. With that in mind I had an idea that needed to use the possible combinations of a set with repetition, so I said to myself "yea i can make this in construct!" here I am two weeks later. I have had success with a method to get it done but I think it can be better. Any help is very much appreciated. Thanks!

    https://dl.dropboxusercontent.com/u/17757267/combination.capx

    My attempt, I made a different event sheet for my other tries, so its all included.

  • One way to do it:

    a holds the values

    b is a helping array

    d keeps the combinations

    Care, the repeat will do it all in one tick - if you intend to do that with larger sets, I suggest using some kind of limit of how many iterations you do each tick (mby like 500-1000).

  • Here's another way. It's basically to change a 10-base number to a "array.width"-base using Array element as symbols.

  • Thank you mindfaQ & Magistross I was able to figure out what each line does in each solution.

    I have a question for Magistross. When I comment out event 16 "set baseNumber....", why does it still list the combinations successfully? My understanding is that in the "positions" loop that line is what sets the "baseNumber" for the value for the 3 items in the "Combo" variable.

  • Sorry for the delay, It's quite impossible that you can still get all the combinations after you comment out the "Set baseNumber" of line 16. This line is responsible for getting all the "digits" right. Otherwise, you will get combinations which all have the same characters appearing at each position. (e.g. "aaa", "bbb", "ccc", "aaa", "bbb", ...)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you I found out why I was getting that "problem", I forgot to switch my event sheet to the one that has your solution in it. As you you said it is indeed impossible to get the combinations.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)