Merge pull request #2049 from def-/permutations
Add nextPermutation and prevPermutation
This commit is contained in:
commit
08ee62a783
2 changed files with 78 additions and 0 deletions
19
tests/stdlib/tpermutations.nim
Normal file
19
tests/stdlib/tpermutations.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
discard """
|
||||
output: '''@[0, 2, 1]
|
||||
@[1, 0, 2]
|
||||
@[1, 2, 0]
|
||||
@[2, 0, 1]
|
||||
@[2, 1, 0]
|
||||
@[2, 0, 1]
|
||||
@[1, 2, 0]
|
||||
@[1, 0, 2]
|
||||
@[0, 2, 1]
|
||||
@[0, 1, 2]'''
|
||||
"""
|
||||
import algorithm
|
||||
|
||||
var v = @[0, 1, 2]
|
||||
while v.nextPermutation():
|
||||
echo v
|
||||
while v.prevPermutation():
|
||||
echo v
|
||||
Loading…
Add table
Add a link
Reference in a new issue