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.

12345678910111213
  1. module ArmstrongNumbers
  2. let intFromChar a = int a - int '0'
  3. // a ^ b where they are both ints
  4. let rec intPow (a: int) (b: int) =
  5. if b = 0 then 1 else a * (intPow a (b - 1))
  6. let isArmstrongNumber (number: int): bool =
  7. let len = String.length (string (number))
  8. number =
  9. (Seq.toList (string (number))
  10. |> Seq.fold (fun a c -> a + (intPow (intFromChar c) len)) 0)