Created
November 26, 2019 04:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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