Working with sequences

2024-05-20 Thread Zoom
const a = [1, 2, 3] b = [-1, 2, 5] c = [1, -2, 4] s = [a, b, c] block original: var x, y, z: seq[int] for arr in s: x.add(arr[0]) y.add(arr[1]) z.add(arr[2]) echo [min(x), min(y), min(z)] #(-1, -2, 3)

Working with sequences

2024-05-20 Thread allanmax3321
You're absolutely right, there's a more efficient way to find the minimums in Nim! Here's how you can achieve the same result without creating temporary sequences: Using fold: The fold function in Nim allows you to accumulate a value based on each element in a sequence. Here's how you can use

Working with sequences

2024-05-19 Thread namisboss
Personally I would just use a single array to store the output values because they don't interact with each other. type Vec*[N: static[int], V] = array[N, V] Vec3*[V] = Vec[3, V] var a = Vec3[int]([1, 2, 3]) b = Vec3[int]([-1, 2, 5]) c

Working with sequences

2024-05-19 Thread Nello41
Hey, I'm a Nim beginner and i would like to know if there is a smarter and faster way to do the following. I'm trying to find the minimum of a sequence as the array wchose component are whose components are the minimum of the components of the elements of the sequence. What I am doing is creati