Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module FizzBuzz =
- let matchFizzBuzz i =
- match (i, i%3=0, i%5=0) with
- | (i, true, true) -> sprintf "%A FizzBuzz" i
- | (i, true, false) -> sprintf "%A Fizz" i
- | (i, false, true) -> sprintf "%A Buzz" i
- | (i, false, false) -> sprintf "%A" i
- let fizzBuzz =
- List.iter(fun i -> printfn "%A" (matchFizzBuzz i)) [1..20]
- module Bisects =
- let isBisect year =
- match year with
- | year when year % 400 = 0 -> Some(year)
- | year when year % 100 = 0 -> None
- | year when year % 4 = 0 -> Some(year)
- | _ -> None
- let chooseLeapYears =
- [ 1900; 2000; 2016; 2017 ]
- |> List.choose isBisect
- |> List.iter (printfn "%d")
- module Timey =
- let duration list =
- match list with
- | [] -> 0
- | [ s ] -> s
- | [ m; s ] -> m * 60 + s
- | h :: m :: s :: _ -> h * 3600 + m * 60 + s
- module Shapes =
- open System
- type Shape =
- | Rectangle of height : float * width : float
- | Circle of radius : float
- let area shape =
- match shape with
- | Rectangle(h, w) -> h*w
- | Circle(r) -> Math.PI * r * r
- let rec readValidFloat () =
- let input = Console.ReadLine()
- let ok, num = Double.TryParse input
- match ok, num with
- | true, num when num > 0.0 -> num
- | _, _ -> readValidFloat()
- let rec validChoice() =
- printf "Shape type: "
- let shapeType = Console.ReadLine()
- match shapeType with
- | "C" | "c" -> 'C'
- | "D" | "d" -> 'D'
- | _ -> validChoice()
- let inputRectangle() =
- printfn "Introduceti lungimea:"
- let h = readValidFloat()
- printfn "Introduceti latimea:"
- let w = readValidFloat()
- Rectangle(h,w)
- let inputCircle() =
- printfn "Introduceti raza:"
- Circle(readValidFloat())
- let inputShape() =
- printfn "Introduceti D pentru dreptunghi si C pentru cerc: "
- if validChoice() = 'D' then inputRectangle()
- else inputCircle()
- [<EntryPoint>]
- let main argv =
- FizzBuzz.fizzBuzz
- Bisects.chooseLeapYears
- printfn "--------------------------------------"
- printfn "%d" (Timey.duration [23; 9; 5; 1; 4])
- printfn "%d" (Timey.duration [])
- printfn "%d" (Timey.duration [3])
- printfn "%d" (Timey.duration [2; 30])
- let s = Shapes.inputShape()
- printfn "Aria figurii '%A' este: %.2f" s (Shapes.area s)
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement