Merge pull request #2049 from def-/permutations

Add nextPermutation and prevPermutation
This commit is contained in:
Andreas Rumpf 2015-02-04 17:12:35 +01:00
commit 08ee62a783
2 changed files with 78 additions and 0 deletions

View 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