メインメニューを開く

差分

フィボナッチ数/F Sharp

297 バイト追加, 2012年4月26日 (木) 14:26
<source lang="fsharp">
let rec fib x =
match x with | x when x <= 0 0I -> failwith "1以上の整数が必要です"0I | 1 1I -> 11I | 2 2I -> 11I | x -> fib (x - 11I) + fib (x - 22I) [0I .. 15I] |> Seq.iter (fun x -> printfn "fib(%O) = %O" x (fib x));;</source> == 記述例2 ==<source lang="fsharp">let fib x = let rec loop acc1 acc2 = function | x when x <= 0I -> acc1 | x -> loop acc2 (acc1 + acc2) (x - 1I) loop 0I 1I x [0I .. 15I] |> Seq.iter (fun x -> printfn "fib(%dO) = %O" x (fib 15x));;
</source>
匿名利用者