commit 27e959bc85e74413bd142d37355106ad6ac109f0 Author: Francesco Minnocci Date: Wed Mar 30 17:31:43 2022 +0200 First Commit diff --git a/esperimenti/.config/dotnet-tools.json b/esperimenti/.config/dotnet-tools.json new file mode 100644 index 0000000..b6be3c7 --- /dev/null +++ b/esperimenti/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fsautocomplete": { + "version": "0.51.0", + "commands": [ + "fsautocomplete" + ] + } + } +} \ No newline at end of file diff --git a/esperimenti/.ionide/symbolCache.db b/esperimenti/.ionide/symbolCache.db new file mode 100644 index 0000000..9cf02ad Binary files /dev/null and b/esperimenti/.ionide/symbolCache.db differ diff --git a/esperimenti/Program.fs b/esperimenti/Program.fs new file mode 100644 index 0000000..8b41b49 --- /dev/null +++ b/esperimenti/Program.fs @@ -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"))) diff --git a/esperimenti/esperimenti.fsproj b/esperimenti/esperimenti.fsproj new file mode 100644 index 0000000..b3c42bf --- /dev/null +++ b/esperimenti/esperimenti.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + + diff --git a/fib/.config/dotnet-tools.json b/fib/.config/dotnet-tools.json new file mode 100644 index 0000000..b6be3c7 --- /dev/null +++ b/fib/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fsautocomplete": { + "version": "0.51.0", + "commands": [ + "fsautocomplete" + ] + } + } +} \ No newline at end of file diff --git a/fib/.ionide/symbolCache.db b/fib/.ionide/symbolCache.db new file mode 100644 index 0000000..9615ea4 Binary files /dev/null and b/fib/.ionide/symbolCache.db differ diff --git a/fib/Program.fs b/fib/Program.fs new file mode 100644 index 0000000..ad7d986 --- /dev/null +++ b/fib/Program.fs @@ -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)) diff --git a/fib/fib.fsproj b/fib/fib.fsproj new file mode 100644 index 0000000..b3c42bf --- /dev/null +++ b/fib/fib.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + + diff --git a/lab3/.config/dotnet-tools.json b/lab3/.config/dotnet-tools.json new file mode 100644 index 0000000..b6be3c7 --- /dev/null +++ b/lab3/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fsautocomplete": { + "version": "0.51.0", + "commands": [ + "fsautocomplete" + ] + } + } +} \ No newline at end of file diff --git a/lab3/.ionide/symbolCache.db b/lab3/.ionide/symbolCache.db new file mode 100644 index 0000000..89a5946 Binary files /dev/null and b/lab3/.ionide/symbolCache.db differ diff --git a/lab3/Program.fs b/lab3/Program.fs new file mode 100644 index 0000000..72b95c7 --- /dev/null +++ b/lab3/Program.fs @@ -0,0 +1,8 @@ +let sni x = + if x > 3 then + 101 + else + failwith "ok" + +printfn "%A" (sni 4) +printfn "%A" (sni 2) diff --git a/lab3/lab3.fsproj b/lab3/lab3.fsproj new file mode 100644 index 0000000..b3c42bf --- /dev/null +++ b/lab3/lab3.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + + diff --git a/ludo/.config/dotnet-tools.json b/ludo/.config/dotnet-tools.json new file mode 100644 index 0000000..b6be3c7 --- /dev/null +++ b/ludo/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fsautocomplete": { + "version": "0.51.0", + "commands": [ + "fsautocomplete" + ] + } + } +} \ No newline at end of file diff --git a/ludo/.ionide/symbolCache.db b/ludo/.ionide/symbolCache.db new file mode 100644 index 0000000..a310069 Binary files /dev/null and b/ludo/.ionide/symbolCache.db differ diff --git a/ludo/Program.fs b/ludo/Program.fs new file mode 100644 index 0000000..9708eb6 --- /dev/null +++ b/ludo/Program.fs @@ -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)) diff --git a/ludo/ludo.fsproj b/ludo/ludo.fsproj new file mode 100644 index 0000000..b3c42bf --- /dev/null +++ b/ludo/ludo.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + + diff --git a/mc91/.config/dotnet-tools.json b/mc91/.config/dotnet-tools.json new file mode 100644 index 0000000..b6be3c7 --- /dev/null +++ b/mc91/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fsautocomplete": { + "version": "0.51.0", + "commands": [ + "fsautocomplete" + ] + } + } +} \ No newline at end of file diff --git a/mc91/.ionide/symbolCache.db b/mc91/.ionide/symbolCache.db new file mode 100644 index 0000000..f980108 Binary files /dev/null and b/mc91/.ionide/symbolCache.db differ diff --git a/mc91/Program.fs b/mc91/Program.fs new file mode 100644 index 0000000..2c60211 --- /dev/null +++ b/mc91/Program.fs @@ -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)) diff --git a/mc91/mc91.fsproj b/mc91/mc91.fsproj new file mode 100644 index 0000000..b3c42bf --- /dev/null +++ b/mc91/mc91.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + +