import math
import sequtils
import typetraits
const
a = @[1, 2, 3, 4, 5]
b = @[1, 2, 3, 4, 5]
var
vandermonde: seq[seq[int]]
row: seq[int]
vandermonde = newSeq[seq[int]]()
for i, aa in a:
row = newSeq[int]()
vandermonde.add(row)
for j, bb in b:
vandermonde[i].add(aa^bb)
#echo vandermonde
# @[@[1, 1, 1, 1, 1], @[2, 4, 8, 16, 32], @[3, 9, 27, 81, 243], @[4, 16, 64, 256, 1024], @[5, 25, 125, 625, 3125]]
proc flatten*[T](a: seq[T]): seq[T] =
static:
echo "flatten*[T](a: seq[T]): seq[T]"
echo T.name
result = a
proc flatten*[T](a: seq[seq[T]]): seq[T] =
static:
echo "flatten*[T](a: seq[seq[T]]): seq[T]"
echo T.name
result = a.concat.flatten
#echo vandermonde.flatten()
# @[1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 3, 9, 27, 81, 243, 4, 16, 64, 256, 1024, 5, 25, 125, 625, 3125]
let t = @[
@[
@[1,2,3],
@[1,2,3]
],
@[
@[3,2,1],
@[3,2,1]
],
@[
@[4,4,5],
@[4,4,4]
]
]
#echo t
# @[@[@[1, 2, 3], @[1, 2, 3]], @[@[3, 2, 1], @[3, 2, 1]], @[@[4, 4, 5], @[4, 4, 4]]]
# echo flatten(t)
# xxxxx.nim(24, 44) Error: type mismatch: got (seq[int]) but expected 'seq[seq[int]]'
#let p = @[@[1,2,3,4,5]]
let p = @[@[@[1,2,3,4,5]]]
echo flatten(p)
# @[1, 2, 3, 4, 5]