Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Nth-root/CoffeeScript/nth-root-1.coffee
Normal file
26
Task/Nth-root/CoffeeScript/nth-root-1.coffee
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
nth_root = (A, n, precision=0.0000000000001) ->
|
||||
x = 1
|
||||
while true
|
||||
x_new = (1 / n) * ((n - 1) * x + A / Math.pow(x, n - 1))
|
||||
return x_new if Math.abs(x_new - x) < precision
|
||||
x = x_new
|
||||
|
||||
# tests
|
||||
do ->
|
||||
tests = [
|
||||
[8, 3]
|
||||
[16, 4]
|
||||
[32, 5]
|
||||
[343, 3]
|
||||
[1024, 10]
|
||||
[1000000000, 3]
|
||||
[1000000000, 9]
|
||||
[100, 2]
|
||||
[100, 3]
|
||||
[100, 5]
|
||||
[100, 10]
|
||||
]
|
||||
for test in tests
|
||||
[x, n] = test
|
||||
root = nth_root x, n
|
||||
console.log "#{x} root #{n} = #{root} (root^#{n} = #{Math.pow root, n})"
|
||||
12
Task/Nth-root/CoffeeScript/nth-root-2.coffee
Normal file
12
Task/Nth-root/CoffeeScript/nth-root-2.coffee
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
> coffee nth_root.coffee
|
||||
8 root 3 = 2 (root^3 = 8)
|
||||
16 root 4 = 2 (root^4 = 16)
|
||||
32 root 5 = 2 (root^5 = 32)
|
||||
343 root 3 = 7 (root^3 = 343)
|
||||
1024 root 10 = 2 (root^10 = 1024)
|
||||
1000000000 root 3 = 1000 (root^3 = 1000000000)
|
||||
1000000000 root 9 = 10 (root^9 = 1000000000)
|
||||
100 root 2 = 10 (root^2 = 100)
|
||||
100 root 3 = 4.641588833612778 (root^3 = 99.99999999999997)
|
||||
100 root 5 = 2.5118864315095806 (root^5 = 100.0000000000001)
|
||||
100 root 10 = 1.5848931924611134 (root^10 = 99.99999999999993)
|
||||
Loading…
Add table
Add a link
Reference in a new issue