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 LFIT(x,y): | |
| N = len(x) | |
| if N != len(y): | |
| return 0 | |
| Sx = sum(x) | |
| Sy = sum(y) | |
| Sx2 = sum([n**2 for n in x]) | |
| Sxy = sum([x[i]*y[i] for i in range(N)]) | |
| b = (N*Sxy-Sx*Sy)/(N*Sx2-Sx**2) | |
| a = (Sy-b*Sx)/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
| <?php | |
| function highestCommonFactor($array){ | |
| $hcf = 1; | |
| $totalItems = count($array); | |
| $smaller = $array[$totalItems-1]; | |
| for($i = 0; $i<$totalItems; $i++){ | |
| $temp = $array[$i]; | |
| if($array[$i]<0) { | |
| $temp = -1*$temp; |
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
| <?php | |
| function degree($polynomial){ | |
| for($i = (count($polynomial)-1); $i>=0; $i--){ | |
| if($polynomial[$i]!=0){ | |
| return $i; | |
| } | |
| } | |
| return 0; | |
| } | |
| function formatPolynomial($poly){ |
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
| import math | |
| def tree_ref(tree, index): | |
| if(isinstance(index,(list,tuple)) and (len(index)>1)): | |
| #print tree | |
| #print index | |
| #print "--1---" | |
| newTree = tree[index[0]] | |
| #print newTree | |
| newIndex = tuple([index[k] for k in range(1,len(index))]) | |
| #print newIndex |
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 depth(expr): | |
| depthLevel = 0 | |
| if(isinstance(expr,(list,tuple))==False): | |
| return 0 | |
| else: | |
| depthLevel += 1 | |
| if( isinstance(expr[1],(list,tuple)) ): | |
| biggestDepth = 0 | |
| for i in range(1,len(expr)): | |
| depthOfCurrentTerm = depth(expr[i]) |
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 count_pattern(pattern, lst): | |
| lenP = len(pattern) | |
| #print("lenP",lenP) | |
| lenL = len(lst) | |
| #print("lenL",lenL) | |
| total = 0 | |
| if(lenL >= lenP): | |
| for i in range(0, lenL): | |
| #print("repetition #:"+str(i)) | |
| match = False |
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 trapezoidalSum(xRange,n): | |
| tot = 0 | |
| width = 0 | |
| width = (xRange[1]-xRange[0])/n | |
| x = [ interval for interval in arange(xRange[0],xRange[1]+width, width) ] | |
| yRange = [ y(n) for n in x ] | |
| tot += yRange[0]+yRange[n] | |
| tot += sum([ 2*yRange[i] for i in range(1,n) ]) | |
| tot = tot*width/2 | |
| return tot |
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
| from numpy import * | |
| def simpsonSum(xRange,n): | |
| tot = 0 | |
| width = 0 | |
| width = (xRange[1]-xRange[0])/n | |
| x = [ interval for interval in arange(xRange[0],xRange[1]+width, width) ] | |
| yRange = [ y(n) for n in x ] | |
| tot += yRange[0]+yRange[n] | |
| tot += sum([ 2*yRange[i] if (i%2==0) else 4*yRange[i] for i in range(1,n) ]) | |
| tot = tot*width/3 |
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
| import requests | |
| import json | |
| import wikipedia | |
| def retrieveQuestions(dataStr): | |
| dataStr = dataStr.lower() | |
| questions = [] | |
| another_question = False | |
| w_s = ["what","why","when","how","have","can","could"] | |
| w_c = "" | |
| pos_i = 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
| import math | |
| def calcSide(a): | |
| side = math.sqrt(2) | |
| H = math.sqrt(1/2) | |
| for x in range(1,a): | |
| b = side/2 | |
| x = 1 - H | |
| side = math.sqrt(b**2+x**2) | |
| H = math.sqrt(1-(side/2)**2) | |
| r = {"side":side,"H":H} |