Sha256: 1f918e2b8204184d712a24fd3076ccbf99d7141d298707253a918f2c30336cc6

Contents?: true

Size: 292 Bytes

Versions: 214

Compression:

Stored size: 292 Bytes

Contents

object CollatzCalculator {

    fun computeStepCount(start: Int): Int {
        require(start > 0) { "Only natural numbers are allowed" }

        if (start == 1) return 0

        val next = if (start % 2 == 0) start / 2 else 3 * start + 1
        return 1 + computeStepCount(next)
    }

}

Version data entries

214 entries across 214 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.138 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.137 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.136 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.135 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.134 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.133 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.132 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.131 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.130 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.129 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.128 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.127 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.126 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.125 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.124 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.123 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.122 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.121 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.120 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt