/**
 * Convert a list of polar representations of complex numbers to cartesian form.
 *
 * @param polarNums A list of pairs representing the magnitude and argument of complex numbers in polar form.
 * @return A list of complex numbers in cartesian form.
 *
 * Example:
 * val polarNums = listOf(Pair(2.0, 0.0), Pair(3.0, 1.5708), Pair(1.0, 3.1416))
 * polarToCartesian(polarNums)
 * Output: [(2+0i), (1.8369701987210297E-16+3i), (-1+1.2246467991473532E-16i)]
 */
import kotlin.math.cos
import kotlin.math.sin


fun polarToCartesian(polarNums: List<Pair<Double, Double>>): List<Complex> {

    val cartesianNums = mutableListOf<Complex>()
    for (polarNum in polarNums) {
        val (magnitude, argument) = polarNum
        val real = magnitude * cos(argument)
        val imag = magnitude * sin(argument)
        cartesianNums.add(Complex(real, imag))
    }
    return cartesianNums
}

data class Complex(val real: Double, val imag: Double) {
    override fun toString(): String {
        return "($real+${imag}i)"
    }
}
import kotlin.math.cos
import kotlin.math.sin

/**
 * Convert a list of polar representations of complex numbers to cartesian form.
 *
 * @param polarNums A list of pairs representing the magnitude and argument of complex numbers in polar form.
 * @return A list of complex numbers in cartesian form.
 *
 * Example:
 * val polarNums = listOf(Pair(2.0, 0.0), Pair(3.0, 1.5708), Pair(1.0, 3.1416))
 * polarToCartesian(polarNums)
 * Output: [(2+0i), (1.8369701987210297E-16+3i), (-1+1.2246467991473532E-16i)]
 */
fun polarToCartesian(polarNums: List<Pair<Double, Double>>): List<Complex> {
import kotlin.math.cos
import kotlin.math.sin

/**
 * Convert a list of polar representations of complex numbers to cartesian form.
 *
 * @param polarNums A list of pairs representing the magnitude and argument of complex numbers in polar form.
 * @return A list of complex numbers in cartesian form.
 *
 * Example:
 * val polarNums = listOf(Pair(2.0, 0.0), Pair(3.0, 1.5708), Pair(1.0, 3.1416))
 * polarToCartesian(polarNums)
 * Output: [(2+0i), (1.8369701987210297E-16+3i), (-1+1.2246467991473532E-16i)]
 */
fun polarToCartesian(polarNums: List<Pair<Double, Double>>): List<Complex> {

    val cartesianNums = mutableListOf<Complex>()
    for (polarNum in polarNums) {
        val (magnitude, argument) = polarNum
        val real = magnitude * cos(argument)
        val imag = magnitude * sin(argument)
        cartesianNums.add(Complex(real, imag))
    }
    return cartesianNums
}

data class Complex(val real: Double, val imag: Double) {
    override fun toString(): String {
        return "($real+${imag}i)"
    }
}