Sha256: 74c304db68f97abedb2c0aa4eabd35f171364823455c62b0101e442f2bd1b970

Contents?: true

Size: 451 Bytes

Versions: 134

Compression:

Stored size: 451 Bytes

Contents

module CollatzConjecture exposing (collatz)


collatz : Int -> Result String Int
collatz start =
    if start <= 0 then
        Err "Only positive numbers are allowed"
    else
        Ok (collatzHelper 0 start)


collatzHelper : Int -> Int -> Int
collatzHelper steps start =
    if start == 1 then
        steps
    else if start % 2 == 0 then
        collatzHelper (1 + steps) (start // 2)
    else
        collatzHelper (1 + steps) (3 * start + 1)

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.179 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.178 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.177 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.176 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.175 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.174 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.173 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.172 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.171 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.170 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.169 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.167 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.166 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.165 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.164 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.163 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.162 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.161 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm
trackler-2.2.1.160 tracks/elm/exercises/collatz-conjecture/CollatzConjecture.example.elm