This file contains 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
# Solving this problem: | |
# http://projecteuler.net/problem=2 | |
# Sum: 4,613,732 | |
def fab(a,b, maxlimit): | |
while b < maxlimit: | |
yield b | |
a, b = b, a+b | |
This file contains 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
# Using Sieve of Eratosthenes | |
# https://en.wikipedia.org/wiki/Generating_primes | |
import sys | |
def main(): | |
num = int(sys.argv[1]) | |
num_list = [[i,True] for i in range(num)] | |
num_list[0][1] = False | |
num_list[1][1] = False |
This file contains 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
# Let's have a list x = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]] | |
# How to convert it into x = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4] | |
x = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]] | |
# We thuse use reduce. | |
# When given a list, it goes throgu each pair of items from left to right, | |
# and applied some function on them. | |
# Remember, [1,3] + [2,4] => [1, 3, 2, 4] |
This file contains 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 dict_load(s): | |
d = {} | |
for c in s: | |
if c == " ": | |
pass | |
else: | |
d[c] = d.get(c, 0) + 1 | |
return d | |
def dict_unload(s, d): |
This file contains 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
# Solution for Kaggle Digit Recognizer | |
# <https://www.kaggle.com/c/digit-recognizer> | |
# | |
# You need to install sklearn | |
# Solution done using Rocchio (Nearest Centroid) | |
# | |
# Get train and test data files from here:: | |
# <https://www.kaggle.com/c/digit-recognizer/data> | |
# | |
# Author: Tarek Amr (@gr33ndata) |
This file contains 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
<html> | |
<head> | |
<script type='text/javascript' src='https://www.google.com/jsapi'></script> | |
<script type='text/javascript'> | |
google.load('visualization', '1', {'packages': ['geochart']}); | |
google.setOnLoadCallback(drawMarkersMap); | |
function drawMarkersMap() { | |
var data = google.visualization.arrayToDataTable([ | |
['City', 'Factories', 'Factories'], |
This file contains 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 qsort(x): | |
if x == []: | |
return x | |
less = [] | |
more = [] | |
for item in x[1:]: | |
if item < x[0]: | |
less.append(item) | |
else: | |
more.append(item) |
This file contains 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
function latlng(address){ | |
var response = Maps.newGeocoder().geocode(address); | |
if (response.status == "OK"){ | |
var result = response.results[0]; | |
return '' + result.geometry.location.lat + ',' + result.geometry.location.lat + ''; | |
} | |
else{ | |
return '0,0'; | |
} | |
}; |
This file contains 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 time import sleep | |
from multiprocessing import Pool | |
def fun(i): | |
if i % 2: | |
sleep(2) | |
print i | |
pool = Pool(4) | |
pool.map(fun,range(40)) |
This file contains 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 sklearn.linear_model import LinearRegression | |
from sklearn.preprocessing import PolynomialFeatures | |
x = [[1],[4],[7],[13],[10]] | |
# Y1 = 10 + 6*x | |
y1 = [16, 34, 52, 88, 70] | |
# Y2 = x*x = x^2 | |
y2 = [1, 16, 49, 169, 100] | |
# This will convert X into |
OlderNewer