Factorial

import org.junit.Test import kotlin.test.assertEquals class FactorialTest { @Test fun `Test factorial results`() { val numberWithFactorial = mapOf( 0 to 1L, 1 to 1L, 2 to 2L, 3 to 6L, 4 to 24L, 10 to 3628800L, 15 to 1307674368000L, 20 to 2432902008176640000L ) for ((i, factorialResult) in numberWithFactorial) { assertEquals(factorialResult, factorial(i)) } } } // Your code starts here //sampleStart fun factorial(n: Int): Long = [mark]TODO()[/mark] //sampleEnd
Save Restore Add own tests Switch to main Feedback

A factorial is a product of all the numbers from 0 to that number. For example factorial(5) = 5! = 5 * 4 * 3 * 2 * 1 = 120. More here.


Previous
Next