Created
May 14, 2024 04:08
-
-
Save DrunkenAlcoholic/a99edd9f82590295702a356460c61caa to your computer and use it in GitHub Desktop.
Collatz Conjecture [Exercism - Nim]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc steps*(n: int): int = | |
if n < 1: raise (ref ValueError)() | |
var Num = n | |
while Num > 1: | |
inc(result) | |
if Num mod 2 == 0: | |
Num = Num div 2 | |
else: | |
Num = Num * 3 + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment