re: Challenge: Write your worst program VIEW POST

FULL DISCUSSION
 

Multiplication should be hard

EDIT Improved version

fun multiply(a: Int, b: Int): Int {
    tailrec fun multiplyRec(a: Int, b: Int, acc: Int = 0): Int =
        when (b) {
            0 -> acc
            else -> multiplyRec(a, b - 1, acc + a)
        }

    return multiplyRec(a, b)
}
code of conduct - report abuse