object Luhn {
    fun isValid(inpString: String): Boolean {
        try {
            val processedString: String = inpString.replace(" ", "")
            if (processedString.length <= 1) return false
            val reversed = processedString.reversed()

            val build: StringBuilder = StringBuilder()
            for (i in 0..reversed.length - 1){
                if ((i + 1) % 2 != 1){
                    val temp = reversed[i].toString().toInt() * 2
                    build.append(if (temp > 9){ temp - 9 } else {temp})
                }
                else {build.append(reversed[i])}
            }
            return (build.sumBy { it.toString().toInt() } % 10 ==0)
        }
        catch (e: NumberFormatException){ return false }
    }
}