class IsbnVerifier {
    fun isValid(inputString: String): Boolean {
        var count = 10
        val filteredString = inputString.filter { it != '-' }
        return if ((filteredString.all { it == 'X' || it.isDigit() })
            && ((filteredString.indexOfFirst { it == 'X' } == 9)
               || (filteredString.indexOfFirst { it == 'X' } == -1))
            && (filteredString.length == 10)
        ) {
            (filteredString
                .fold(0) { acc, c ->
                    if (c == 'X') {
                        count--
                        acc + (10 * (count + 1))
                    } else {
                        count--
                        acc + ((c.toInt() - 48) * (count + 1))
                    }
                }.rem(11) == 0)
        } else false
    }
}
