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.0.5 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.2.0.4 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.2.0.3 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.2.0.2 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.2.0.1 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.2.0.0 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.55 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.54 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.53 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.52 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.51 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.50 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.49 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.48 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.47 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.46 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.45 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.44 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.43 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt
trackler-2.1.0.42 tracks/kotlin/exercises/collatz-conjecture/src/example/kotlin/CollatzCalculator.kt