Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.26 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. (* Zadanie 6 *)
  5.  
  6. let rec srednia iloczyn ilosc suma =
  7.     let input = System.Convert.ToDouble(System.Console.ReadLine())
  8.     let sredniaGeo(iloczyn: float, ilosc: float) = System.Math.Pow(iloczyn, 1.0/ilosc)
  9.  
  10.     if input = 0.0 then (
  11.         if ilosc <> 0.0
  12.         then (sredniaGeo(iloczyn, ilosc), suma)
  13.         else (System.Double.NaN, System.Double.NaN)
  14.     )
  15.     else srednia (iloczyn * input) (ilosc + 1.0) (suma + input)
  16.  
  17.  
  18. (* Zadanie 7 *)
  19.  
  20. type StarType = Left | Right | Both
  21.  
  22. let drawStars(rowCount: int, starType: StarType) =
  23.     let rec drawLeft(counter) =
  24.         if counter <= rowCount then (
  25.            let spacesCount = rowCount - counter
  26.            let spaces = List.init spacesCount (fun i -> " ")
  27.            let stars = List.init (rowCount - spacesCount) (fun i -> "*")
  28.            let row = spaces @ stars
  29.            System.Console.WriteLine(row |> String.concat "")
  30.            drawLeft(counter + 1)
  31.         )
  32.  
  33.     let rec drawRight(counter) =
  34.         if counter <= rowCount then (
  35.            let spacesCount = rowCount - counter
  36.            let stars = List.init (rowCount - spacesCount) (fun i -> "*")
  37.            System.Console.WriteLine(stars |> String.concat "")
  38.            drawRight(counter + 1)
  39.         )
  40.  
  41.     let rec drawBoth(counter) =
  42.         if counter <= rowCount then (
  43.            let spacesCount = rowCount - counter
  44.            let spaces = List.init spacesCount (fun i -> " ")
  45.            let starsCount = (rowCount - spacesCount) + (rowCount - (rowCount - counter))
  46.            let stars = List.init starsCount (fun i -> "*")
  47.            let row = spaces @ stars
  48.            System.Console.WriteLine(row |> String.concat "")
  49.            drawBoth(counter + 1)
  50.         )
  51.  
  52.     let render starType =
  53.         match starType with
  54.             | StarType.Left -> drawLeft(0)
  55.             | StarType.Right -> drawRight(0)
  56.             | StarType.Both -> drawBoth(0)
  57.             | _ -> drawLeft(0)
  58.    
  59.     render(starType)
  60.  
  61. [<EntryPoint>]
  62. let main argv =
  63.     //printfn "Średnia %A" (srednia 1.0 0.0 0.0)
  64.     drawStars(5, StarType.Right)
  65.     drawStars(5, StarType.Left)
  66.     drawStars(5, StarType.Both)
  67.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement