This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| double computesLN2(double n, double lo, double hi) { | |
| double a = lo, b = hi, m; | |
| while( fabs(a - b) > EPS ) { | |
| m = (a + b) / 2.0; | |
| if( (f( m, n) ) < 0) a = m; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Adrian Statescu <mergesortv@gmail.com | |
| * Natural Logarithm in Golang. | |
| * ln(1) = 0 | |
| */ | |
| package main | |
| import ("fmt" | |
| "os" | |
| "strconv" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def f x,a | |
| Math.exp(x)-a | |
| end | |
| def ln a | |
| lo, hi = 0, a | |
| anEPS = 0.0001 | |
| while (lo-hi).abs >= anEPS | |
| m = ((lo+hi)/2.0).to_f | |
| if f(m,a) < 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add' :: Int -> Int -> Int | |
| add' x y = x + y | |
| mult :: Int -> Int -> Int -> Int | |
| mult x y z = x * y * z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gdc :: Int -> Int -> Int | |
| gdc x y | x == y = x | |
| | x > y = gdc (x - y) y | |
| | x < y = gdc x (y - x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Adrian Statescu <mergesortv@gmail.com> | |
| # Computes SIN using Taylor Series | |
| # | |
| # sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ... | |
| # | |
| # | |
| def fact n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def Subset n | |
| arr = [0]*n | |
| begin | |
| arr[n-1] += 1 | |
| for i in (n-1).downto(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ("fmt" | |
| "os" | |
| "strconv") | |
| func generateSubsets(n int) { | |
| arr := make([]int, n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. | |
| -- What is the 10001st prime number? | |
| import Data.List | |
| square n = n * n | |
| divideBy n x = (x `mod` n) == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # heroku stack:migrate cedar-14 -a <app name> |