Compare commits
1 commit
48b7f0bfef
...
53cc032ca2
Author | SHA1 | Date | |
---|---|---|---|
53cc032ca2 |
1 changed files with 7 additions and 1 deletions
|
@ -87,7 +87,13 @@ private fun isValidIMEI(input: CharSequence): Boolean {
|
|||
|
||||
fun sumOfDigits(input: Int): Int {
|
||||
if (input % 2 == 0) return input
|
||||
return (input * 2).toString().map(Char::digitToInt).sum()
|
||||
var n = input
|
||||
var sum = 0
|
||||
while (n > 0) {
|
||||
sum += n % 10
|
||||
n /= 10
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
val sum = input.dropLast(1).map(Char::digitToInt).sumOf(::sumOfDigits)
|
||||
|
|
Loading…
Add table
Reference in a new issue