Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created October 22, 2022 08:21
Show Gist options
  • Save gonaumov/51f334f0d04bcd6257273e31120ed3f3 to your computer and use it in GitHub Desktop.
Save gonaumov/51f334f0d04bcd6257273e31120ed3f3 to your computer and use it in GitHub Desktop.
package converter
fun main() {
while (true) {
println("Enter two numbers in format: {source base} {target base} (To quit type /exit)")
val userChoice = readln()
if (userChoice == "/exit") {
break;
}
val conversionBases = userChoice.split("\\s+".toRegex()).map {
it.trim().toBigInteger()
}
check(conversionBases.size == 2) {
"You must provide {source base} and {target base}"
}
val (sourceBase, targetBase) = conversionBases
while (true) {
println("Enter number in base $sourceBase to convert to base $targetBase (To go back type /back)")
val conversionInput = readln().trim().split(".")[0]
if (conversionInput.trim().lowercase() == "/back") {
break
}
var numberConverter = NumberConverter(sourceBase, targetBase)
println("Conversion result: ${numberConverter.convert(conversionInput.uppercase())}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment