learning F#, it seems pretty cool, favourite functional language so far.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123456789101112 |
- module CollatzConjecture
-
- let rec countSteps counter n =
- match n with
- | 1 -> counter
- | _ when n % 2 = 0 -> countSteps (counter + 1) (n / 2)
- | _ -> countSteps (counter + 1) (n * 3 + 1)
-
- let steps (number: int): int option =
- match number with
- | _ when number < 1 -> None
- | _ -> Some(countSteps 0 number)
|