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.119 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.118 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.117 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.116 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.115 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.114 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.113 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.111 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.110 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.109 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.108 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.107 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.106 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.105 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.104 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.103 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.102 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.101 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.100 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt
trackler-2.2.1.99 tracks/kotlin/exercises/collatz-conjecture/.meta/src/reference/kotlin/CollatzCalculator.kt