/**
 * This function takes a library catalog and search terms as input, and returns a list of books that match the search terms.
 *
 * @param libraryCatalog A set containing books in the library catalog.
 * @param searchTerms Search terms to filter the books.
 * @return A list of books that match the search terms.
 */
fun searchBooks(libraryCatalog: Set<String>, searchTerms: String): List<String> {

    val matchingBooks = mutableListOf<String>()
    for (book in libraryCatalog) { // Loop through each book in the library catalog
        if (searchTerms in book) { // Check if the search terms are present in the book
            matchingBooks.add(book) // If the search terms match, add the book to the list
        }
        
        if (book == "Harry Potter") { // Check if the book is "Harry Potter"
            if ("fantasy" in searchTerms) { // If the book is "Harry Potter", check if "fantasy" is in the search terms
                matchingBooks.add(book) // If "fantasy" is in the search terms, add the book to the list
            }
        }
    }
    return matchingBooks
}

// Example usage:
val library = setOf(
    "Harry Potter",
    "The Lord of the Rings"
)
/**
 * This function takes a library catalog and search terms as input, and returns a list of books that match the search terms.
 *
 * @param libraryCatalog A set containing books in the library catalog.
 * @param searchTerms Search terms to filter the books.
 * @return A list of books that match the search terms.
 */
fun searchBooks(libraryCatalog: Set<String>, searchTerms: String): List<String> {
/**
 * This function takes a library catalog and search terms as input, and returns a list of books that match the search terms.
 *
 * @param libraryCatalog A set containing books in the library catalog.
 * @param searchTerms Search terms to filter the books.
 * @return A list of books that match the search terms.
 */
fun searchBooks(libraryCatalog: Set<String>, searchTerms: String): List<String> {

    val matchingBooks = mutableListOf<String>()
    for (book in libraryCatalog) { // Loop through each book in the library catalog
        if (searchTerms in book) { // Check if the search terms are present in the book
            matchingBooks.add(book) // If the search terms match, add the book to the list
        }
        
        if (book == "Harry Potter") { // Check if the book is "Harry Potter"
            if ("fantasy" in searchTerms) { // If the book is "Harry Potter", check if "fantasy" is in the search terms
                matchingBooks.add(book) // If "fantasy" is in the search terms, add the book to the list
            }
        }
    }
    return matchingBooks
}

// Example usage:
val library = setOf(
    "Harry Potter",
    "The Lord of the Rings"
)