Skip to content

Instantly share code, notes, and snippets.

@cyrilnoah1
Created November 26, 2019 04:19
Show Gist options
  • Save cyrilnoah1/96286499095601d60c3769e5dee15f7f to your computer and use it in GitHub Desktop.
Save cyrilnoah1/96286499095601d60c3769e5dee15f7f to your computer and use it in GitHub Desktop.
Smallest number with sum of digits as N and divisible by 10^N.
import kotlin.system.*
import kotlin.contracts.*
fun main() {
fun minValue(n : Int){
fun printZeros(){
print("0")
}
fun printNines(){
print("9")
}
fun printInitial(){
val x = n % 9
if(x != 0) print("$x")
}
if(n <= 9){
print("$n")
repeat(n){printZeros()}
}else{
print("${n % 9}")
repeat(n / 9){printNines()}
repeat(n){printZeros()}
}
}
minValue(20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment