Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar

Adrian Statescu thinkphp

View GitHub Profile
@thinkphp
thinkphp / gist:1862871
Created February 19, 2012 09:52
cos(x) in Python
'''
cos(x) = 1-x^2/2!+x^4/4!-x^6/6!+..-
'''
import math
def fact(n):
if n==0:
return 1
else:
return n*fact(n-1)
@thinkphp
thinkphp / gist:1862867
Created February 19, 2012 09:51
sin(x) in Python
'''
sin(x) = x-x^3/3!+x^5/5!-x^7/7!+..-
'''
import math
def fact(n):
if n==0:
return 1
else:
return n*fact(n-1)
@thinkphp
thinkphp / gist:1642162
Created January 19, 2012 19:51
Insertion Sort pseudocode
/*
Pseudocode of the complete algorithm
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
*/
INSERTION-SORT(V)
@thinkphp
thinkphp / gist:1642099
Created January 19, 2012 19:40
Insertion Sort in Python
'''
Insertion Sort
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
'''
def insertionSort(arr):
@thinkphp
thinkphp / gist:1642090
Created January 19, 2012 19:38
Insertion Sort in PHP
/**
Insertion Sort in PHP
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
*/
function insertionSort($arr){
$n = count($arr);
@thinkphp
thinkphp / gist:1641985
Created January 19, 2012 19:29
Insertion Sort in JavaScript
/*
Insertion Sort in JavaScript
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
*/
function insertionSort(arr) {
var n = arr.length-1,
@thinkphp
thinkphp / gist:1543590
Created December 31, 2011 10:07
Computes square root in Python SQRT
'''
Computes SQuare RooT in Python SQRT
s = (s+nr/s)1/2
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
'''
@thinkphp
thinkphp / gist:1529713
Created December 28, 2011 21:00
Ln in Python
'''
x
f(x) = e - a
if f(0)*f(a) < 0 then exists the solution (0,a]
'''
import math
import sys
def loge(n,li,ls):
if math.fabs(li-ls) <= 0.000001:
@thinkphp
thinkphp / gist:1528363
Created December 28, 2011 15:32
e in Python
'''
Computes the value of e(2.718281827...) using infinite series
Twitter: @thinkphp
Website: http://thinkphp.ro
G+ : http://gplus.to/thinkphp
MIT Style License
1 + 1/1! + 1/2! + 1/3! + ...
2 + 1/2! + 1/3!+ ...
'''
@thinkphp
thinkphp / gist:1501320
Created December 20, 2011 11:48
math.pi
'''
Calculate the value of PI using Infinite Series
Twitter: @thinkphp
Website: http://thinkphp.ro
G+ : http://gplus.to/thinkphp
MIT Style License
4*(1- 1/3 + 1/5 - 1/7 + 1/9 +...)
'''
import math