complex number code

func arrayComplexElementsProduct(real: [Int], imag: [Int]) -> [Int] {
    var x = real[0]
    var y = imag[0]
    for i in 1..<real.count {
        let a = x*real[i] - y*imag[i]
        let b = x*imag[i] + y*real[i]
        x = a
        y = b
    }
    return [x,y]
}

Comments

Popular posts from this blog

josephusProblem(

Functions in python you should know about - String.capwords()