summary refs log tree commit diff stats
path: root/tests/iter/tcomplex_openarray.nim
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2016-08-25 22:59:51 +0800
committerJacek Sieka <arnetheduck@gmail.com>2016-08-25 22:59:51 +0800
commitdb2f96daba9c04db2f24cb783c79fb37799cd9ea (patch)
tree567beb43c7e4549abfcae1ea66e5232d7525e001 /tests/iter/tcomplex_openarray.nim
parent3116744c86f37ac4e4e5fec3d6d1635304ed717f (diff)
parent84a09d2f5b0866491e55fef0fef541e8cc548852 (diff)
downloadNim-db2f96daba9c04db2f24cb783c79fb37799cd9ea.tar.gz
Merge remote-tracking branch 'origin/devel' into initallocator-fix
Diffstat (limited to 'tests/iter/tcomplex_openarray.nim')
-rw-r--r--tests/iter/tcomplex_openarray.nim33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/iter/tcomplex_openarray.nim b/tests/iter/tcomplex_openarray.nim
new file mode 100644
index 000000000..6fc191e90
--- /dev/null
+++ b/tests/iter/tcomplex_openarray.nim
@@ -0,0 +1,33 @@
+
+# bug #3221
+
+import algorithm, math, sequtils
+
+
+iterator permutations[T](ys: openarray[T]): seq[T] =
+  var
+    d = 1
+    c = newSeq[int](ys.len)
+    xs = newSeq[T](ys.len)
+  for i, y in ys: xs[i] = y
+  yield xs
+  block outer:
+    while true:
+      while d > 1:
+        dec d
+        c[d] = 0
+      while c[d] >= d:
+        inc d
+        if d >= ys.len: break outer
+      let i = if (d and 1) == 1: c[d] else: 0
+      swap xs[i], xs[d]
+      yield xs
+      inc c[d]
+
+proc dig_vectors(): void =
+  var v_nums: seq[int]
+  v_nums = newSeq[int](1)
+  for perm in permutations(toSeq(0 .. 1)):
+    v_nums[0] = 1
+
+dig_vectors()