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 write(file_path, sequence, line_format): | |
""" | |
Example Usage: Save squares of numbers from 1 to 100 in a csv file | |
squares = ( (i, i * i) for i in range(1, 101)) | |
write("squares.txt", squares, "{},{}") | |
""" | |
lines = (line_format.format(*line_variables) for line_variables in sequence) |
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
import collections | |
import functools | |
#https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize | |
class memoized(object): | |
'''Decorator. Caches a function's return value each time it is called. | |
If called later with the same arguments, the cached value is returned | |
(not reevaluated). | |
''' |
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
#https://www.youtube.com/watch?v=UZjlBQbV1KU | |
x <- seq(0, 1, length=100) | |
a= 0.5 | |
b= 0.5 | |
y <- x^(a-1) * (1-x)^(b-1) | |
plot(x, y, type="l", lwd=3) |
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
""" | |
Problem Description: | |
You are given three vessels A, B and C of capacities 8, 5 and 3 gallons respectively. A is filled, while B and C are empty. | |
Divide the liquid in A into two equal quantities. | |
(From Graph Theory, Narsingh Deo) | |
http://bit.ly/1Dnp4HA | |
Usage: | |
import decanting as dc | |
import networkx as nx |
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 __future__ import division | |
import random | |
import itertools | |
""" | |
People are waiting in line to board a 100-seat airplane. Steve is the first person in the line. He gets on the plane but suddenly can't remember what his seat number is, so he picks a seat at random. After that, each person who gets on the plane sits in their assigned seat if it's available, otherwise they will choose an open seat at random to sit in. | |
The flight is full and you are last in line. What is the probability that you get to sit in your assigned seat? | |
Usage: | |
python monte.py |
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 random import randint | |
import ipdb | |
RAND_MAX = 1000 | |
class Node(object): | |
def __init__(self, key, data, priority=None): | |
self.key = key | |
self.data = data | |
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 collections import namedtuple | |
from itertools import combinations | |
Rod = namedtuple('Rod', ['length', 'price', ]) | |
def optimal_price(rods,total_length=20): | |
zero_rod = Rod(length=0,price=0) | |
if total_length > len(rods): |
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
Show hidden characters
// While you can edit this file, it's best to put your changes in | |
// "User/Preferences.sublime-settings", which overrides the settings in here. | |
// | |
// Settings may also be placed in file type specific options files, for | |
// example, in Packages/Python/Python.sublime-settings for python files. | |
{ | |
// Sets the colors used within the text area | |
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", | |
// Note that the font_face and font_size are overriden in the platform |
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
import Queue | |
import threading | |
class PrintMsg(threading.Thread): | |
def __init__(self,queue): | |
threading.Thread.__init__(self) | |
self.queue = queue | |
def run(self): | |
while True: | |
print "waiting for msg" | |
msg = self.queue.get() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.