/**
 * This function calculates the reaction forces at the supports of a beam due to the given loads.
 *
 * @param loads A list containing the loads applied on the beam. Each load is represented as a pair with two elements:
 *              (load magnitude, distance from support)
 * @return A pair containing the reaction forces at the supports. The first element represents the force at the left support
 *         and the second element represents the force at the right support.
 */
fun calculateBeamReactionForces(loads: List<Pair<Double, Double>>): Pair<Double, Double> {

    // Initialize the reaction forces at the supports to zero
    var leftSupportForce = 0.0
    var rightSupportForce = 0.0

    // Iterate through each load and calculate the reaction forces
    val totalDistance = loads.sumByDouble { it.second }
    for (load in loads) {
        val (loadMagnitude, distance) = load

        // Calculate the contribution of the load to the reaction forces
        leftSupportForce += loadMagnitude * (distance / totalDistance)
        rightSupportForce += loadMagnitude * (1 - distance / totalDistance)
    }

    return Pair(leftSupportForce, rightSupportForce)
}
/**
 * This function calculates the reaction forces at the supports of a beam due to the given loads.
 *
 * @param loads A list containing the loads applied on the beam. Each load is represented as a pair with two elements:
 *              (load magnitude, distance from support)
 * @return A pair containing the reaction forces at the supports. The first element represents the force at the left support
 *         and the second element represents the force at the right support.
 */
fun calculateBeamReactionForces(loads: List<Pair<Double, Double>>): Pair<Double, Double> {
/**
 * This function calculates the reaction forces at the supports of a beam due to the given loads.
 *
 * @param loads A list containing the loads applied on the beam. Each load is represented as a pair with two elements:
 *              (load magnitude, distance from support)
 * @return A pair containing the reaction forces at the supports. The first element represents the force at the left support
 *         and the second element represents the force at the right support.
 */
fun calculateBeamReactionForces(loads: List<Pair<Double, Double>>): Pair<Double, Double> {

    // Initialize the reaction forces at the supports to zero
    var leftSupportForce = 0.0
    var rightSupportForce = 0.0

    // Iterate through each load and calculate the reaction forces
    val totalDistance = loads.sumByDouble { it.second }
    for (load in loads) {
        val (loadMagnitude, distance) = load

        // Calculate the contribution of the load to the reaction forces
        leftSupportForce += loadMagnitude * (distance / totalDistance)
        rightSupportForce += loadMagnitude * (1 - distance / totalDistance)
    }

    return Pair(leftSupportForce, rightSupportForce)
}