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.18 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.17 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.16 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.15 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.14 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.13 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.12 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.11 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.10 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.9 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.8 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.7 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.6 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.5 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.4 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.3 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.2 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.1 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.0 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt
trackler-2.2.0.6 tracks/kotlin/exercises/prime-factors/src/example/kotlin/PrimeFactorCalculator.kt