/**
 * This function takes a list of connections in an electrical circuit and checks for infinite loops.
 * It returns true if there is an infinite loop and false otherwise.
 */
fun checkCircuit(connections: List<Pair<String, String>>): Boolean {

    // Create an empty set to store the connections already visited
    val visited = mutableSetOf<String>()

    // Initialize a flag variable to indicate the presence of an infinite loop
    var hasInfiniteLoop = false

    // Iterate through each connection
    for (connection in connections) {
        // Check if the connection has already been visited
        if (connection.first in visited) {
            hasInfiniteLoop = true
            break
        }

        // Add the connection to the visited set
        visited.add(connection.first)
    }

    return hasInfiniteLoop
}

// Scenario: Checking for infinite loops in a complex electrical circuit

// Connections in the circuit represented by pairs of (startNode, endNode)
// Each connection represents a wire connection between two components

val connections = listOf(
    "A" to "B",
    "B" to "C",
    "C" to "D",
    "D" to "E",
    "E" to "F",
    "G" to "H",
    "H" to "I",
    "I" to "J",
    "J" to "K"
)
/**
 * This function takes a list of connections in an electrical circuit and checks for infinite loops.
 * It returns true if there is an infinite loop and false otherwise.
 */
fun checkCircuit(connections: List<Pair<String, String>>): Boolean {
/**
 * This function takes a list of connections in an electrical circuit and checks for infinite loops.
 * It returns true if there is an infinite loop and false otherwise.
 */
fun checkCircuit(connections: List<Pair<String, String>>): Boolean {

    // Create an empty set to store the connections already visited
    val visited = mutableSetOf<String>()

    // Initialize a flag variable to indicate the presence of an infinite loop
    var hasInfiniteLoop = false

    // Iterate through each connection
    for (connection in connections) {
        // Check if the connection has already been visited
        if (connection.first in visited) {
            hasInfiniteLoop = true
            break
        }

        // Add the connection to the visited set
        visited.add(connection.first)
    }

    return hasInfiniteLoop
}

// Scenario: Checking for infinite loops in a complex electrical circuit

// Connections in the circuit represented by pairs of (startNode, endNode)
// Each connection represents a wire connection between two components

val connections = listOf(
    "A" to "B",
    "B" to "C",
    "C" to "D",
    "D" to "E",
    "E" to "F",
    "G" to "H",
    "H" to "I",
    "I" to "J",
    "J" to "K"
)