learning F#, it seems pretty cool, favourite functional language so far.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CollatzConjecture.fs 335B

123456789101112
  1. module CollatzConjecture
  2. let rec countSteps counter n =
  3. match n with
  4. | 1 -> counter
  5. | _ when n % 2 = 0 -> countSteps (counter + 1) (n / 2)
  6. | _ -> countSteps (counter + 1) (n * 3 + 1)
  7. let steps (number: int): int option =
  8. match number with
  9. | _ when number < 1 -> None
  10. | _ -> Some(countSteps 0 number)