/**
 * You are a Marketing Manager and you need to modify the prices of products by applying a discount.
 *
 * Given a list of prices and a discount value between 0 and 1, modify each price in the list by reducing it with the discount amount.
 *
 * Write a Kotlin function that takes the list of prices and the discount value as input, and returns a new list with the modified prices.
 *
 * Example:
 * modifyPrices(listOf(10.0, 20.0, 30.0), 0.2) ➞ [8.0, 16.0, 24.0]
 *
 * Note:
 * - The discount value should be a float value between 0 and 1 (inclusive).
 * - Round the modified prices to one decimal place.
 * - The input list should not be modified, create a new list with the modified prices.
 */
fun modifyPrices(prices: List<Double>, discount: Double): List<Double> {

    val modifiedPrices = mutableListOf<Double>()
    for (price in prices) {
        modifiedPrices.add((price - (price * discount)).toDouble().round(1))
    }
    return modifiedPrices
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()
/**
 * You are a Marketing Manager and you need to modify the prices of products by applying a discount.
 *
 * Given a list of prices and a discount value between 0 and 1, modify each price in the list by reducing it with the discount amount.
 *
 * Write a Kotlin function that takes the list of prices and the discount value as input, and returns a new list with the modified prices.
 *
 * Example:
 * modifyPrices(listOf(10.0, 20.0, 30.0), 0.2) ➞ [8.0, 16.0, 24.0]
 *
 * Note:
 * - The discount value should be a float value between 0 and 1 (inclusive).
 * - Round the modified prices to one decimal place.
 * - The input list should not be modified, create a new list with the modified prices.
 */
fun modifyPrices(prices: List<Double>, discount: Double): List<Double> {
/**
 * You are a Marketing Manager and you need to modify the prices of products by applying a discount.
 *
 * Given a list of prices and a discount value between 0 and 1, modify each price in the list by reducing it with the discount amount.
 *
 * Write a Kotlin function that takes the list of prices and the discount value as input, and returns a new list with the modified prices.
 *
 * Example:
 * modifyPrices(listOf(10.0, 20.0, 30.0), 0.2) ➞ [8.0, 16.0, 24.0]
 *
 * Note:
 * - The discount value should be a float value between 0 and 1 (inclusive).
 * - Round the modified prices to one decimal place.
 * - The input list should not be modified, create a new list with the modified prices.
 */
fun modifyPrices(prices: List<Double>, discount: Double): List<Double> {

    val modifiedPrices = mutableListOf<Double>()
    for (price in prices) {
        modifiedPrices.add((price - (price * discount)).toDouble().round(1))
    }
    return modifiedPrices
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()