Skip to content

Instantly share code, notes, and snippets.

@kimji1
Created August 8, 2020 02:01
Show Gist options
  • Select an option

  • Save kimji1/63c448815d10f8b07e341f54fa48369f to your computer and use it in GitHub Desktop.

Select an option

Save kimji1/63c448815d10f8b07e341f54fa48369f to your computer and use it in GitHub Desktop.
codility
fun main() {
println(solution(28))
println(solution(734))
println(solution(1990))
println(solution(1000))
}
fun solution(N: Int): Int {
val target = sumOfDisassembledN(N)
var n = N
do {
n += 1
val sum = sumOfDisassembledN(n)
} while (sum != target)
return n
}
fun sumOfDisassembledN(N: Int): Int {
var sum = 0
var n = N
while (n > 0) {
sum += n % 10
n /= 10
}
return sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment