Skip to content

Instantly share code, notes, and snippets.

@avighnash
Created March 19, 2019 03:59
Show Gist options
  • Save avighnash/1daf3df6a5d67b8cfa39e06fd5c94f96 to your computer and use it in GitHub Desktop.
Save avighnash/1daf3df6a5d67b8cfa39e06fd5c94f96 to your computer and use it in GitHub Desktop.
package com.avighnash.exercises
object AdditivePersistence {
fun calc(num: Long): Int {
var x = num
var i = 0
while (x.toString().toCharArray().map(Character::getNumericValue).size != 1) {
x = x.toString().toCharArray().map(Character::getNumericValue).sum().toLong()
i++
}
return i
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment