/    Sign up×
Community /Pin to ProfileBookmark

What is the best algorithm for…

Does anyone know the most efficient way of iterating through all the possible distinct combinations if you are making X selections from Y unique options; 0<x<=y. For example:

What are all the combinations of cards you could get if you draw cards from a deck of 52 cards.

or

What are all the possible combinations of letters using each letter 0 or 1 times. (a, b, c… ab, ac… abc… but NOT aa. Once ab comes up, ba should not come up.)

The order of selections does not matter.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottSep 26.2003 — There are formulas and techniques for calculating combinations and permutations, but there is no shortcut if you need to iterate through them all.
×

Success!

Help @jacen6678 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...