1

Topic: All combinations of numbers from digits

There is number 123. It is necessary to write algorithm of obtaining of all combinations of numbers that is it is necessary to receive 123 132 213 231 312 321

2

Re: All combinations of numbers from digits

Hello, Kodt, you wrote: and further - std:: next_permutation in a cycle. Most likely the person also asks how to implement this next_permutation.

3

Re: All combinations of numbers from digits

Hello, e.thrash, you wrote: ET> There is number 123. ET> It is necessary to write algorithm of obtaining of all combinations of numbers ET> that is It take necessary to receive ET> 123 ET> 132 ET> 213 ET> 231 ET> 312 ET> 321 each digit from the list and we put in head of the new list. For each new list we take each of the remained digits, we copy the current list and we put its following number. And so yet we do not sort out all. It is implemented through a recursive function. Approximately here so: import sys arr = [int (c) for c in sys.argv [1]] print arr print "" def get_permutations (inp, out = []): if not len (inp): print out return for i, d in enumerate (inp): inp2 = list (inp) out2 = list (out) out2.append (d) del inp2 [i] get_permutations (inp2, out2) get_permutations (arr)

4

Re: All combinations of numbers from digits

Hello, e.thrash, you wrote: ET> There is number 123. ET> It is necessary to write algorithm of obtaining of all combinations of numbers of Algoriti Hipa does not approach? https://en.wikipedia.org/wiki/Heap%27s_algorithm