You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
937 B
Forth
48 lines
937 B
Forth
// For more information see https://aka.ms/fsharp-console-apps
|
|
printfn "Hello from F#"
|
|
|
|
// printfn "%A" ((fun x -> x+1)3)
|
|
|
|
let ratio(x,y) =
|
|
let z = x * y
|
|
let w = 2 * (x + y)
|
|
w / z
|
|
|
|
let ratio2(x : float, y : float) =
|
|
let z = x * y
|
|
let w = ((2 : float) * x) + ((2 : float) * y)
|
|
w / z
|
|
|
|
printfn "%A" (ratio2(2.1,3.0))
|
|
|
|
let getType(x) = x.GetType().FullName
|
|
|
|
let rec Fib (n : int) =
|
|
if (n = 0 || n = 1) then 1
|
|
else Fib (n - 1) + Fib (n - 2)
|
|
|
|
let TrNum (n : int) = n*(n+1)/2
|
|
|
|
printfn "%A" (TrNum(10))
|
|
|
|
let rec ProdNum (n : int) =
|
|
match n with
|
|
| 1 -> 1
|
|
| _ -> ProdNum(n-1)*n
|
|
|
|
let rec sumFirstFun f k =
|
|
if k<=0 then 0 else f k + sumFirstFun f (k-1)
|
|
|
|
let rec fold g f k1 k2 z =
|
|
if (k2 < k1) then z
|
|
else g (fold g f (k1+1) k2 z) (f(k1))
|
|
|
|
let sum x y = x + y
|
|
let double x = 2*x
|
|
|
|
printfn "%A" (fold sum double 10 100 0)
|
|
|
|
printfn "%A" (ProdNum(5))
|
|
|
|
printfn "%A" (Fib (5))
|