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.159 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.158 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.157 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.156 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.155 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.154 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.153 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.152 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.151 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.150 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.149 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.148 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.147 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.146 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.145 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.144 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.143 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.142 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.141 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt
trackler-2.2.1.140 tracks/kotlin/exercises/prime-factors/.meta/src/reference/kotlin/PrimeFactorCalculator.kt