Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- open System
- let rec geoAvg (product: float, amount: int, sum: float) =
- let s = System.Console.ReadLine()
- let d = System.Convert.ToDouble(s)
- if d <> 0.0 then geoAvg(d * product, amount + 1, sum + d)
- else (product ** (1.0 / System.Convert.ToDouble(amount)), sum)
- let rec middlePyramid (size: int, row: int, column: int) =
- if row >= size then ()
- else
- if column < size * 2 then
- if column < size - row || column > size + row then printf " "
- else printf "*"
- middlePyramid (size, row, column + 1)
- else
- printf "\n"
- middlePyramid (size, row + 1, 0)
- let rec leftPyramid (size: int, row: int, column: int) =
- if row > size then ()
- else
- if column < size then
- if column < row then printf "*"
- else printf " "
- leftPyramid (size, row, column + 1)
- else
- printf "\n"
- leftPyramid (size, row + 1, 0)
- let rec rightPyramid (size: int, row: int, column: int) =
- if row > size then ()
- else
- if column < size then
- if column < size - row then printf " "
- else printf "*"
- rightPyramid (size, row, column + 1)
- else
- printf "\n"
- rightPyramid (size, row + 1, 0)
- let pyramid (size: int) =
- if size > System.Console.WindowHeight || size > System.Console.WindowWidth then ()
- else rightPyramid (size, 0, 0)
- let rec dividers (target: int, current: int, result: int list) =
- if target / 2 < current then result
- elif target % current = 0 then dividers (target, current + 1, current::result)
- else dividers (target, current + 1, result)
- let dividersMain (target: int) =
- dividers(target, 2, [])
- let rec sorter (nums: float list, result: float list) =
- if (nums.Length >= 2) then
- let x1 = nums.[0]
- let x2 = nums.[1]
- let rest = nums.[2..]
- if x1 > x2 then
- sorter(x2::rest, x1::result)
- else
- sorter(x1::rest, x2::result)
- elif nums.Length = 1 then
- result @ nums
- else result
- let checkIndex (list: float list, target: float) =
- List.length (List.filter (fun x -> x < target) (list))
- let rec sorter2 (nums: float list, result: float list) =
- if (nums.Length >= 1) then
- let x1 = nums.[0]
- let rest = nums.[1..]
- let idx = checkIndex (result, x1)
- sorter2 (rest, result.[..idx] @ [x1] @ result.[idx + 1..])
- else result
- let rec task10 current =
- let k = current / 4
- if k * 4 + 1 = current then true
- elif k * 4 + 3 = current then false
- elif current % 2 = 0 then task10 (current / 2)
- else false
- [<EntryPoint>]
- let main argv =
- //printfn "%A" (geoAvg (1.0, 0, 0.0))
- //pyramid (5)
- //printf "%A" (dividersMain (100))
- //printf "%b" (task10 17)
- //printf "%b" (task10 19)
- //printf "%b" (task10 20)
- //printf "%b" (task10 3)
- printf "%A" (sorter2 ([1.0; 2.0; 0.3; 4.0; 5.3; 3.3; 2.33; 2.32], []))
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement