Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.net
- // See the 'F# Tutorial' project for more help.
- (* Zadanie 6 *)
- let rec srednia iloczyn ilosc suma =
- let input = System.Convert.ToDouble(System.Console.ReadLine())
- let sredniaGeo(iloczyn: float, ilosc: float) = System.Math.Pow(iloczyn, 1.0/ilosc)
- if input = 0.0 then (
- if ilosc <> 0.0
- then (sredniaGeo(iloczyn, ilosc), suma)
- else (System.Double.NaN, System.Double.NaN)
- )
- else srednia (iloczyn * input) (ilosc + 1.0) (suma + input)
- (* Zadanie 7 *)
- type StarType = Left | Right | Both
- let drawStars(rowCount: int, starType: StarType) =
- let rec drawLeft(counter) =
- if counter <= rowCount then (
- let spacesCount = rowCount - counter
- let spaces = List.init spacesCount (fun i -> " ")
- let stars = List.init (rowCount - spacesCount) (fun i -> "*")
- let row = spaces @ stars
- System.Console.WriteLine(row |> String.concat "")
- drawLeft(counter + 1)
- )
- let rec drawRight(counter) =
- if counter <= rowCount then (
- let spacesCount = rowCount - counter
- let stars = List.init (rowCount - spacesCount) (fun i -> "*")
- System.Console.WriteLine(stars |> String.concat "")
- drawRight(counter + 1)
- )
- let rec drawBoth(counter) =
- if counter <= rowCount then (
- let spacesCount = rowCount - counter
- let spaces = List.init spacesCount (fun i -> " ")
- let starsCount = (rowCount - spacesCount) + (rowCount - (rowCount - counter))
- let stars = List.init starsCount (fun i -> "*")
- let row = spaces @ stars
- System.Console.WriteLine(row |> String.concat "")
- drawBoth(counter + 1)
- )
- let render starType =
- match starType with
- | StarType.Left -> drawLeft(0)
- | StarType.Right -> drawRight(0)
- | StarType.Both -> drawBoth(0)
- | _ -> drawLeft(0)
- render(starType)
- [<EntryPoint>]
- let main argv =
- //printfn "Średnia %A" (srednia 1.0 0.0 0.0)
- drawStars(5, StarType.Right)
- drawStars(5, StarType.Left)
- drawStars(5, StarType.Both)
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement