We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 01a36a7 commit 9d18825Copy full SHA for 9d18825
nimplex.nim
@@ -0,0 +1,34 @@
1
+# Copyrigth (C) 2023 Adam M. Krajewski
2
+
3
+import std/math
4
+import arraymancer
5
+import strutils
6
7
+proc simplex_grid*(m: int,
8
+ n: int): Tensor[int] =
9
+ let L: int = binom(n+m-1, m-1)
10
+ result = newTensor[int]([L, m])
11
+ var x = zeros[int](m)
12
+ x[m-1] = n
13
+ for j in 0..m-1:
14
+ result[0, j] = x[j]
15
+ var h = m
16
+ for i in 1..L-1:
17
+ h -= 1
18
+ let val = x[h]
19
+ x[h] = 0
20
+ x[m-1] = val - 1
21
+ x[h-1] += 1
22
23
+ result[i, j] = x[j]
24
+ if val != 1:
25
+ h = m
26
+ return result
27
28
+echo "Simplex dimensions:"
29
+let m = readLine(stdin).parseInt()
30
31
+echo "N divisions:"
32
+let n = readLine(stdin).parseInt()
33
34
+echo simplex_grid(m, n)
0 commit comments