/**
 * Given a list representing an athlete's movements and the number of steps,
 * return the count of steps performed in the given direction.
 *
 * The athlete's movements are represented as a list of logical 'true' (for forward)
 * and 'false' (for backward) values. Each movement represents one step.
 *
 * Example:
 * countSteps(listOf(true, true, false, true, false, true), 3) -> 2
 *
 * In the above example, the athlete moves forward for the first three steps,
 * then moves backward for the next three steps. So, the count of forward steps is 2.
 *
 * You need to implement the 'countSteps' function to solve the exercise.
 */
fun countSteps(athlete: List<Boolean>, steps: Int): Int {

    var forwardSteps = 0
    var backwardSteps = 0
    var currentDirection = true

    for (movement in athlete) {
        if (movement == currentDirection) {
            forwardSteps++
        } else {
            backwardSteps++
        }

        // Update currentDirection
        if (forwardSteps > backwardSteps) {
            currentDirection = true
        } else if (forwardSteps < backwardSteps) {
            currentDirection = false
        }
    }

    return if (currentDirection) forwardSteps else backwardSteps
}
/**
 * Given a list representing an athlete's movements and the number of steps,
 * return the count of steps performed in the given direction.
 *
 * The athlete's movements are represented as a list of logical 'true' (for forward)
 * and 'false' (for backward) values. Each movement represents one step.
 *
 * Example:
 * countSteps(listOf(true, true, false, true, false, true), 3) -> 2
 *
 * In the above example, the athlete moves forward for the first three steps,
 * then moves backward for the next three steps. So, the count of forward steps is 2.
 *
 * You need to implement the 'countSteps' function to solve the exercise.
 */
fun countSteps(athlete: List<Boolean>, steps: Int): Int {
/**
 * Given a list representing an athlete's movements and the number of steps,
 * return the count of steps performed in the given direction.
 *
 * The athlete's movements are represented as a list of logical 'true' (for forward)
 * and 'false' (for backward) values. Each movement represents one step.
 *
 * Example:
 * countSteps(listOf(true, true, false, true, false, true), 3) -> 2
 *
 * In the above example, the athlete moves forward for the first three steps,
 * then moves backward for the next three steps. So, the count of forward steps is 2.
 *
 * You need to implement the 'countSteps' function to solve the exercise.
 */
fun countSteps(athlete: List<Boolean>, steps: Int): Int {

    var forwardSteps = 0
    var backwardSteps = 0
    var currentDirection = true

    for (movement in athlete) {
        if (movement == currentDirection) {
            forwardSteps++
        } else {
            backwardSteps++
        }

        // Update currentDirection
        if (forwardSteps > backwardSteps) {
            currentDirection = true
        } else if (forwardSteps < backwardSteps) {
            currentDirection = false
        }
    }

    return if (currentDirection) forwardSteps else backwardSteps
}