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 creating new sequences (x, y, and z) that pertain to the 
individual components and then I use the default min procedure. In my opinion, 
this is stupid and not optimal in terms of memory usage and efficiency. Do you 
have any advice for me? Thanks
    
    
    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 = Vec3[int]([1, -2, 4])
        s = @[a, b, c]
    
    var
        x: seq[int]
        y: seq[int]
        z: seq[int]
    
    for i in 0..<s.len:
        x.add(s[i][0])
        y.add(s[i][1])
        z.add(s[i][2])
    
    
    echo x      # 1, -1, 1
    echo y      # -1, 2, 5
    echo z      # 1, -2, 4
    
    echo Vec3[int]([min(x), min(y), min(z)])    #(-1, -2, 3)
    
    
    
    Run

Reply via email to