Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- // See the 'F# Tutorial' project for more help.
- module Sandbox =
- let factorial n =
- let rec fact n acc =
- if n <= 1 then
- acc
- else
- fact (n - 1) (acc * n)
- fact n 1
- let mainSb() =
- factorial 7
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- module Program1=
- let read nr =
- printf "Latura %d: > " nr
- int(System.Console.ReadLine())
- let pozitiv x =
- if x > 0 then
- true
- else
- false
- let stri a b c =
- (a + b > c)
- let validate a b c =
- pozitiv a && pozitiv b && pozitiv c && stri a b c && stri b c a && stri c a b
- let mainP1() =
- let a, b, c = read 1, read 2, read 3
- if validate a b c then
- printfn "Triunghi"
- else
- printfn "Nu e triunghi"
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- module Program2 =
- let and' a b = a && b
- let or' a b = a || b
- let not' a = not a
- let xor' a b = and' (or' a b) (or' (not' a) (not' b))
- let f1 a b = and' a (or' a (not' b))
- let f2 a b = xor' a b
- let printLine f a b =
- printfn "%A\t%A\t%A" a b (f a b)
- let printTable f =
- printLine f false false
- printLine f false true
- printLine f true false
- printLine f true true
- let mainP2() =
- printfn "a\tb\tf1 = a * (a + !b)"
- printTable f1
- printfn "\n"
- printfn "a\tb\tf2 = a ^ b"
- printTable f2
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- module Program3 =
- open System
- let sqrtRecursive x =
- let rec sqrt' x b =
- if (b * b - x) > 1e-12 then
- sqrt' x (((x/b) + b)/2.0)
- else
- b
- sqrt' x x
- let mainP3() =
- printfn "Radical recursiv.\n\tIntroduceti numarul:"
- let nr = float(System.Console.ReadLine())
- printfn "sqrt (%A) = %A" nr (sqrtRecursive nr)
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- module Program4 =
- let rec guess nr x =
- printfn "Ghiceste numarul [0, 100]; Incercari ramase: %A" x
- if (x > 0) then
- let myguess = int(System.Console.ReadLine())
- if (myguess = nr) then
- printfn("Felicitari! Ai castigat!");
- else
- guess nr (x-1)
- else
- printfn("Ai pierdut!")
- let mainP4() =
- let nr = (new System.Random()).Next(100)
- printfn "%A" nr
- guess nr 7
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- [<EntryPoint>]
- let main argv =
- //printfn "%A" (Sandbox.mainSb())
- printfn "- - - - Verificare triunghi - - - - "
- Program1.mainP1()
- printfn "- - - - Tabele adevar - - - - "
- Program2.mainP2()
- printfn "- - - - Radical - - - - "
- Program3.mainP3()
- printfn "- - - - Ghiceste numarul - - - - "
- Program4.mainP4()
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement