Sha256: 59807a50c2c7205a437c408efb9072e9177d0d09db8f284672b9ba0d1083cb24

Contents?: true

Size: 527 Bytes

Versions: 188

Compression:

Stored size: 527 Bytes

Contents

object PrimeFactorCalculator {

    fun primeFactors(int: Int): List<Int> {
        return primeFactors(int.toLong()).map(Long::toInt)
    }

    fun primeFactors(long: Long): List<Long> {
        val result = mutableListOf<Long>()
        var remainder = long
        var divisor: Long = 2

        while (remainder > 1) {
            while (remainder.rem(divisor) == 0L) {
                result.add(divisor)
                remainder /= divisor
            }

            divisor++
        }

        return result
    }

}

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.57 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.56 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.55 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.54 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.53 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.52 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.51 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.50 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.49 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.48 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.47 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.46 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.45 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.44 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.43 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.42 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.41 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.40 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.39 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt