A
A
Anton Baryshev2021-04-27 20:05:11
.NET
Anton Baryshev, 2021-04-27 20:05:11

How to perform placement of k elements out of n?

Hello! It is necessary to create an elegant algorithm for finding placement. Specifically, you need to place 7 elements out of 8. The algorithms that I saw on the Internet work with numeric arrays, and I have an array of characters (chars). All combinations must be saved, because. then a selection will be made among them. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-04-27
@AVollane

Google "placement generation algorithm". For example, this is located .
Working with symbols is no different from working with numbers. In all languages, characters can be compared by their codes, and there is nothing in algorithms other than comparison.
Or you can generate placements from {1,2,3,...N} and then use those numbers in the placements as character indexes. Draw characters from the given string at these positions and get the placement of characters, not numbers.

M
Mercury13, 2021-04-27
@Mercury13

Will there be reruns?
If not, then it is enough to sort char's and use a numerical algorithm.
If there are, look for "postings with repetitions" and sort them too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question