This commit is contained in:
DavidOnTop 2025-01-15 08:39:24 +01:00
commit 03e7be38dd
Signed by: DavidOnTop
GPG key ID: 8D3E9A75E3E13D89
8 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,7 @@
module UlohyFs.Attributes
open System
type UlohaAttribute(id: int) =
inherit Attribute()
member _.Id = id

30
ulohyfs/src/Program.fs Normal file
View file

@ -0,0 +1,30 @@
module UlohyFs.Program
open System
open System.Reflection
open UlohyFs.Attributes
[<EntryPoint>]
let main args =
let ulohy =
Assembly.GetExecutingAssembly().GetTypes()
|> Array.map _.GetMethods()
|> Array.collect id
|> Array.filter (fun m -> m.GetCustomAttributes(typeof<UlohaAttribute>, false).Length > 0)
printfn "Zadaj cislo ulohy:"
let uloha = Console.ReadLine()
let uloha = Convert.ToInt32(uloha)
let ulohameta =
ulohy
|> Array.map (fun m -> (
let ua =
m.GetCustomAttributes(typeof<UlohaAttribute>, false)
|> Array.map (fun a -> a :?> UlohaAttribute)
(ua[0], m)
))
|> Array.find (fun (a, _) -> a.Id = uloha)
let _, m = ulohameta
m.Invoke(null, null) |> ignore
0

24
ulohyfs/src/u15.fs Normal file
View file

@ -0,0 +1,24 @@
module UlohyFs.u15
open System.IO
open System.Text.Unicode
open UlohyFs.Attributes
open System
let path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/spokojnost.txt"
let npath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/nespokojnost.txt"
[<Uloha(15)>]
let uloha15() =
let spokojnost =
File.ReadAllLines(path)
|> Array.map (fun l -> Convert.ToInt32(l))
let nfile = File.Create(npath)
spokojnost |> Array.iter (fun s -> (
if s <= 5 then
nfile.Write(Text.Encoding.UTF8.GetBytes(s.ToString() + "\n"))
))
nfile.Flush()
nfile.Close()
printfn "Pocet zakaznikov: %d" spokojnost.Length
printfn "Priemer: %f" (spokojnost |> Array.map (fun f -> float f) |> Array.average)

16
ulohyfs/src/u16.fs Normal file
View file

@ -0,0 +1,16 @@
module UlohyFs.u16
open System
open UlohyFs.Attributes
[<Uloha(16)>]
let uloha16() =
let original = "mATURITNÁ SKÚŠKA Z iNFORMATIKY"
let added = sprintf $"{original} aktuálny rok, v ktorom maturujete"
printfn "%s" added
original.IndexOf "SKÚŠKA"
|> printfn "Index SKÚŠKA: %d"
printfn "inverted case: %s" (original |> Seq.map (fun c -> if Char.IsLower c then Char.ToUpper c else Char.ToLower c) |> Seq.toArray |> System.String)
printfn "replaced %s" (original.Replace("Informatiky", "Programovania"))
printfn "all operations: %s" (added |> Seq.map (fun c -> if Char.IsLower c then Char.ToUpper c else Char.ToLower c) |> Seq.toArray |> System.String |> fun s -> s.Replace("Informatiky", "Programovania"))

15
ulohyfs/src/u17.fs Normal file
View file

@ -0,0 +1,15 @@
module UlohyFs.u17
open System.IO
open UlohyFs.Attributes
open System
let eur2usd euro =
euro * 1.0245
[<Uloha(17)>]
let uloha15() =
printfn "Eur?: "
let eur = System.Console.ReadLine() |> float
let usd = eur2usd eur
printfn "USD: %f" usd

17
ulohyfs/ulohyfs.fsproj Normal file
View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>UlohyFs</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="src\Attributes.fs" />
<Compile Include="src\u16.fs" />
<Compile Include="src\u15.fs" />
<Compile Include="src\u17.fs" />
<Compile Include="src\Program.fs" />
</ItemGroup>
</Project>