First Commit
commit
27e959bc85
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"fsautocomplete": {
|
||||
"version": "0.51.0",
|
||||
"commands": [
|
||||
"fsautocomplete"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,23 @@
|
||||
let containsAs (s : string) =
|
||||
String.filter (fun c -> c = 'a') s |> String.length
|
||||
|
||||
let numOfStringsContainingAs (str : string []) =
|
||||
str
|
||||
|> Array.map (fun s -> containsAs(s))
|
||||
|> Array.sum
|
||||
|
||||
printfn "%A" (numOfStringsContainingAs [|"ciao";"come";"va"|])
|
||||
printfn "%A" (numOfStringsContainingAs [|"ciaaao";"come";"va"|])
|
||||
|
||||
let numeroPippo x = if x%3 = 1 then Some(x) else None
|
||||
let parolaPippo x = if x = "pippo" then Some(x) else None
|
||||
|
||||
let isPippo (x : option<'a>) =
|
||||
match x with
|
||||
| Some(x) -> true
|
||||
| None -> false
|
||||
|
||||
printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a";"a"|] |> numeroPippo))
|
||||
printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a"|] |> numeroPippo))
|
||||
printfn "%b" (isPippo(parolaPippo("pipo")))
|
||||
printfn "%b" (isPippo(parolaPippo("pippo")))
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"fsautocomplete": {
|
||||
"version": "0.51.0",
|
||||
"commands": [
|
||||
"fsautocomplete"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,14 @@
|
||||
// Modules
|
||||
open System
|
||||
|
||||
// Recursive definition of Fibonacci numbers
|
||||
let rec fib n =
|
||||
match n with
|
||||
| 0 -> 0
|
||||
| 1 -> 1
|
||||
| _ -> fib (n-1) + fib (n-2)
|
||||
|
||||
// Read from stdin and print result
|
||||
printfn "Inserisci l'indice del numero di fibonacci che vuoi calcolare:\n"
|
||||
let i = Console.ReadLine() |> int
|
||||
printfn "%A" (fib (i))
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"fsautocomplete": {
|
||||
"version": "0.51.0",
|
||||
"commands": [
|
||||
"fsautocomplete"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
let sni x =
|
||||
if x > 3 then
|
||||
101
|
||||
else
|
||||
failwith "ok"
|
||||
|
||||
printfn "%A" (sni 4)
|
||||
printfn "%A" (sni 2)
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"fsautocomplete": {
|
||||
"version": "0.51.0",
|
||||
"commands": [
|
||||
"fsautocomplete"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,47 @@
|
||||
// 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))
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"fsautocomplete": {
|
||||
"version": "0.51.0",
|
||||
"commands": [
|
||||
"fsautocomplete"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
// Modules
|
||||
open System
|
||||
|
||||
// Recursive definition
|
||||
let rec mc91 n =
|
||||
if n > 100 then
|
||||
n - 10
|
||||
else
|
||||
mc91 (mc91 (n + 11))
|
||||
|
||||
// Ask for input
|
||||
printfn "Inserisci l'intero in cui calcolare la funzione 91 di McCarthey:\n"
|
||||
let i = Console.ReadLine() |> int
|
||||
|
||||
// Print result
|
||||
printfn "%d" (mc91 (i))
|
Loading…
Reference in New Issue