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
| """ | |
| 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 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
| #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 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 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 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 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 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
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "time" | |
| "os/exec" | |
| ) | |
| func IsAppPublished(url string) bool { |
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
| 0 | 0 | |
|---|---|---|
| 0.01 | 0.000297 | |
| 0.02 | 0.001176 | |
| 0.03 | 0.002619 | |
| 0.04 | 0.004608 | |
| 0.05 | 0.007125 | |
| 0.06 | 0.010152 | |
| 0.07 | 0.013671 | |
| 0.08 | 0.017664 | |
| 0.09 | 0.022113 |
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
| #FlipPredictor | |
| #A coin is drawn at random from a bag of coins of varying probabilities | |
| #Each coin has the same chance of being drawn | |
| #Your class FlipPredictor will be initialized with a list of the probability of | |
| #heads for each coin. This list of probabilities can be accessed as self.coins | |
| #in the functions you must write. The function update will be called after every | |
| #flip to enable you to update your estimate of the probability of each coin being | |
| #the selected coin. The function pheads may be called and any time and will | |
| #return your best estimate of the next flip landing on heads. |
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 os | |
| import time | |
| from watchdog.observers import Observer | |
| from watchdog.events import FileSystemEventHandler | |
| class VHandler(FileSystemEventHandler): | |
| def __init__(self): | |
| FileSystemEventHandler.__init__(self) |
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
| #For simulations | |
| import random | |
| class Item(object): | |
| def __init__(self, value=0, weight=0): | |
| self.value = value | |
| self.weight = weight | |
| def __repr__(self): | |
| return "({value}, {weight})".format(**self.__dict__) |
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 max_weights(a): | |
| weights = [0] * (len(a) + 2) | |
| for i, v in enumerate(a): | |
| j = i + 2 | |
| with_v = weights[j-2] + v | |
| without_v = weights[j-1] | |
| weights[j] = max(with_v, without_v) |