/**
 * A carpenter wants to calculate the total number of work hours for a given list of tasks based on their availability.
 *
 * @param availability A dictionary where the keys represent the days of the week (as strings) and the values represent the number of available hours (as integers) for that day.
 * @param tasks A list of tuples, where each tuple contains the name of the task (as a string) and the estimated number of hours needed to complete that task (as an integer).
 * @return The total number of work hours required for all the tasks.
 */
fun calculateWorkHours(availability: Map<String, Int>, tasks: List<Pair<String, Int>>): Int {

    var totalHours = 0

    for ((day, hours) in availability) {
        for ((task, estimatedHours) in tasks) {
            var remainingHours = hours
            if (remainingHours >= estimatedHours) {
                totalHours += estimatedHours
                remainingHours -= estimatedHours
            } else {
                // Randomly choose between skipping the task or rescheduling it
                if (listOf(true, false).random()) {
                    totalHours += estimatedHours
                    remainingHours = 0
                } else {
                    println("Task '$task' rescheduled due to lack of availability on $day.")
                }
            }
        }
    }

    return totalHours
}
/**
 * A carpenter wants to calculate the total number of work hours for a given list of tasks based on their availability.
 *
 * @param availability A dictionary where the keys represent the days of the week (as strings) and the values represent the number of available hours (as integers) for that day.
 * @param tasks A list of tuples, where each tuple contains the name of the task (as a string) and the estimated number of hours needed to complete that task (as an integer).
 * @return The total number of work hours required for all the tasks.
 */
fun calculateWorkHours(availability: Map<String, Int>, tasks: List<Pair<String, Int>>): Int {
/**
 * A carpenter wants to calculate the total number of work hours for a given list of tasks based on their availability.
 *
 * @param availability A dictionary where the keys represent the days of the week (as strings) and the values represent the number of available hours (as integers) for that day.
 * @param tasks A list of tuples, where each tuple contains the name of the task (as a string) and the estimated number of hours needed to complete that task (as an integer).
 * @return The total number of work hours required for all the tasks.
 */
fun calculateWorkHours(availability: Map<String, Int>, tasks: List<Pair<String, Int>>): Int {

    var totalHours = 0

    for ((day, hours) in availability) {
        for ((task, estimatedHours) in tasks) {
            var remainingHours = hours
            if (remainingHours >= estimatedHours) {
                totalHours += estimatedHours
                remainingHours -= estimatedHours
            } else {
                // Randomly choose between skipping the task or rescheduling it
                if (listOf(true, false).random()) {
                    totalHours += estimatedHours
                    remainingHours = 0
                } else {
                    println("Task '$task' rescheduled due to lack of availability on $day.")
                }
            }
        }
    }

    return totalHours
}