Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar
💭
If I have seen further it is only by standing on the shoulders of giants. Newton

Adrian Statescu thinkphp

💭
If I have seen further it is only by standing on the shoulders of giants. Newton
View GitHub Profile
@thinkphp
thinkphp / ln.c
Created March 17, 2017 07:14
ln.c
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;
@thinkphp
thinkphp / ln.go
Last active February 24, 2021 09:28
Natural Logarithm in Golang.
/*
* Adrian Statescu <mergesortv@gmail.com
* Natural Logarithm in Golang.
* ln(1) = 0
*/
package main
import ("fmt"
"os"
"strconv"
@thinkphp
thinkphp / ln.ruby
Created March 17, 2017 08:12
natural logarithm in ruby
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
@thinkphp
thinkphp / addmult.hs
Created March 20, 2017 20:06
Add And Mult Haskell in Action
add' :: Int -> Int -> Int
add' x y = x + y
mult :: Int -> Int -> Int -> Int
mult x y z = x * y * z
@thinkphp
thinkphp / gdc.hs
Created March 20, 2017 20:09
GDC in Haskell
gdc :: Int -> Int -> Int
gdc x y | x == y = x
| x > y = gdc (x - y) y
| x < y = gdc x (y - x)
@thinkphp
thinkphp / sin.ruby
Created March 21, 2017 13:23
Computes Sin(x) using Taylor Series.
#
# 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
def Subset n
arr = [0]*n
begin
arr[n-1] += 1
for i in (n-1).downto(1)
package main
import ("fmt"
"os"
"strconv")
func generateSubsets(n int) {
arr := make([]int, n)
-- 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
# heroku stack:migrate cedar-14 -a <app name>