/**
 * This exercise requires you to convert a list of complex numbers in polar representation to cartesian representation using list comprehension.
 *
 * Given a list 'points' containing complex numbers in polar form as pairs (magnitude, angle), write a code that returns a list of complex numbers in cartesian form (x + yj).
 *
 * @param points a list of complex numbers in polar representation
 * @return a list of complex numbers in cartesian representation
 *
 * Example:
 * polarToCartesian(listOf(Pair(1.0, 0.0), Pair(2.0, 3.141592653589793), Pair(3.0, 1.5707963267948966)))
 * Output: listOf(Complex(1.0, 0.0), Complex(-2.0, -7.347880794884119E-16), Complex(1.8369701987210297E-16, 3.0))
 */
import kotlin.math.cos
import kotlin.math.sin


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

    return points.map { point ->
        Complex(point.first * cos(point.second), point.first * sin(point.second))
    }
}

data class Complex(val real: Double, val imaginary: Double) {
    override fun toString(): String {
        return "($real${if (imaginary >= 0) "+" else ""}${imaginary}i)"
    }
}
import kotlin.math.cos
import kotlin.math.sin

/**
 * This exercise requires you to convert a list of complex numbers in polar representation to cartesian representation using list comprehension.
 *
 * Given a list 'points' containing complex numbers in polar form as pairs (magnitude, angle), write a code that returns a list of complex numbers in cartesian form (x + yj).
 *
 * @param points a list of complex numbers in polar representation
 * @return a list of complex numbers in cartesian representation
 *
 * Example:
 * polarToCartesian(listOf(Pair(1.0, 0.0), Pair(2.0, 3.141592653589793), Pair(3.0, 1.5707963267948966)))
 * Output: listOf(Complex(1.0, 0.0), Complex(-2.0, -7.347880794884119E-16), Complex(1.8369701987210297E-16, 3.0))
 */
fun polarToCartesian(points: List<Pair<Double, Double>>): List<Complex> {
import kotlin.math.cos
import kotlin.math.sin

/**
 * This exercise requires you to convert a list of complex numbers in polar representation to cartesian representation using list comprehension.
 *
 * Given a list 'points' containing complex numbers in polar form as pairs (magnitude, angle), write a code that returns a list of complex numbers in cartesian form (x + yj).
 *
 * @param points a list of complex numbers in polar representation
 * @return a list of complex numbers in cartesian representation
 *
 * Example:
 * polarToCartesian(listOf(Pair(1.0, 0.0), Pair(2.0, 3.141592653589793), Pair(3.0, 1.5707963267948966)))
 * Output: listOf(Complex(1.0, 0.0), Complex(-2.0, -7.347880794884119E-16), Complex(1.8369701987210297E-16, 3.0))
 */
fun polarToCartesian(points: List<Pair<Double, Double>>): List<Complex> {

    return points.map { point ->
        Complex(point.first * cos(point.second), point.first * sin(point.second))
    }
}

data class Complex(val real: Double, val imaginary: Double) {
    override fun toString(): String {
        return "($real${if (imaginary >= 0) "+" else ""}${imaginary}i)"
    }
}