/**
 * Generate a word square of size n using the given word list.
 *
 * @param n the size of the word square
 * @param wordList a list of words to be used for the word square
 * @return a word square of size n
 *
 * Examples:
 * wordSquare(3, listOf("art", "ram", "tap")) -> listOf(listOf('a', 'r', 't'), listOf('r', 'a', 'm'), listOf('t', 'a', 'p'))
 * wordSquare(4, listOf("oped", "pade", "edit", "dote")) -> listOf(listOf('o', 'p', 'e', 'd'), listOf('p', 'a', 'd', 'e'), listOf('e', 'd', 'i', 't'), listOf('d', 'o', 't', 'e'))
 */
fun wordSquare(n: Int, wordList: List<String>): List<List<Char>> {

    val square = mutableListOf<List<Char>>()
    for (word in wordList) {
        square.add(word.map { it })
    }

    for (row in 1 until n) {
        for (col in 0 until n) {
            square[row] = square[row].toMutableList().apply { set(col, wordList[row][col]) }
        }
    }

    return square
}
/**
 * Generate a word square of size n using the given word list.
 *
 * @param n the size of the word square
 * @param wordList a list of words to be used for the word square
 * @return a word square of size n
 *
 * Examples:
 * wordSquare(3, listOf("art", "ram", "tap")) -> listOf(listOf('a', 'r', 't'), listOf('r', 'a', 'm'), listOf('t', 'a', 'p'))
 * wordSquare(4, listOf("oped", "pade", "edit", "dote")) -> listOf(listOf('o', 'p', 'e', 'd'), listOf('p', 'a', 'd', 'e'), listOf('e', 'd', 'i', 't'), listOf('d', 'o', 't', 'e'))
 */
fun wordSquare(n: Int, wordList: List<String>): List<List<Char>> {
/**
 * Generate a word square of size n using the given word list.
 *
 * @param n the size of the word square
 * @param wordList a list of words to be used for the word square
 * @return a word square of size n
 *
 * Examples:
 * wordSquare(3, listOf("art", "ram", "tap")) -> listOf(listOf('a', 'r', 't'), listOf('r', 'a', 'm'), listOf('t', 'a', 'p'))
 * wordSquare(4, listOf("oped", "pade", "edit", "dote")) -> listOf(listOf('o', 'p', 'e', 'd'), listOf('p', 'a', 'd', 'e'), listOf('e', 'd', 'i', 't'), listOf('d', 'o', 't', 'e'))
 */
fun wordSquare(n: Int, wordList: List<String>): List<List<Char>> {

    val square = mutableListOf<List<Char>>()
    for (word in wordList) {
        square.add(word.map { it })
    }

    for (row in 1 until n) {
        for (col in 0 until n) {
            square[row] = square[row].toMutableList().apply { set(col, wordList[row][col]) }
        }
    }

    return square
}