Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Nth-root/F-Sharp/nth-root.fs
Normal file
21
Task/Nth-root/F-Sharp/nth-root.fs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
let nthroot n A =
|
||||
let rec f x =
|
||||
let m = n - 1.
|
||||
let x' = (m * x + A/x**m) / n
|
||||
match abs(x' - x) with
|
||||
| t when t < abs(x * 1e-9) -> x'
|
||||
| _ -> f x'
|
||||
f (A / double n)
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
if args.Length <> 2 then
|
||||
eprintfn "usage: nthroot n A"
|
||||
exit 1
|
||||
let (b, n) = System.Double.TryParse(args.[0])
|
||||
let (b', A) = System.Double.TryParse(args.[1])
|
||||
if (not b) || (not b') then
|
||||
eprintfn "error: parameter must be a number"
|
||||
exit 1
|
||||
printf "%A" (nthroot n A)
|
||||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue