RosettaCodeData/Task/Bernoulli-numbers/F-Sharp/bernoulli-numbers.fs
2023-07-01 13:44:08 -04:00

25 lines
755 B
FSharp
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

open MathNet.Numerics
open System
open System.Collections.Generic
let calculateBernoulli n =
let (x) = BigRational.FromInt x
let A = Array.init<BigRational> (n+1) (fun x -> (x+1))
for m in [1..n] do
A.[m] <- (1) / ((m) + (1))
for j in [m..(-1)..1] do
A.[j-1] <- (j) * (A.[j-1] - A.[j])
A.[0]
[<EntryPoint>]
let main argv =
for n in [0..60] do
let bernoulliNumber = calculateBernoulli n
match bernoulliNumber.Numerator.IsZero with
| false ->
let formatedString = String.Format("B({0, 2}) = {1, 44} / {2}", n, bernoulliNumber.Numerator, bernoulliNumber.Denominator)
printfn "%s" formatedString
| true ->
printf ""
0