summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2015-02-04 17:12:35 +0100
committerAndreas Rumpf <rumpf_a@web.de>2015-02-04 17:12:35 +0100
commit08ee62a783b82323046c1c64d13a527507935f36 (patch)
treea119130d18a716071454fbe4e3937da0923e3afe /tests
parentb5f1957588c37fc5cef6e26a708f643cc8d0fc70 (diff)
parent03db4d2930bb5265da1d966cd32d7f5faccb6056 (diff)
downloadNim-08ee62a783b82323046c1c64d13a527507935f36.tar.gz
Merge pull request #2049 from def-/permutations
Add nextPermutation and prevPermutation
Diffstat (limited to 'tests')
-rw-r--r--tests/stdlib/tpermutations.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/stdlib/tpermutations.nim b/tests/stdlib/tpermutations.nim
new file mode 100644
index 000000000..a6e07ded6
--- /dev/null
+++ b/tests/stdlib/tpermutations.nim
@@ -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