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 calculate_coins(c, s): | |
#sort the coins | |
c = sorted(c) | |
# remove the coins with values bigger than s | |
c = [ci for ci in filter(lambda cv: cv<=s, c)] | |
# sentinel value to represent that one coin sum is not possible. We can use s + 1 as sentinel value to represent | |
# that case. Mininum value of a coin is 1 so more than s coins can not make a sum of s | |
sentinel = s+1 |
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
""" | |
Knights tour (On 8 * 8 Chessboard) using simple backtracking and no heuristic. | |
To make it generate different solutions I have randomized the part where it selects the next possible move. | |
""" | |
import itertools | |
import random | |
N = 8 | |
N2 = N*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
#Python decorator Example with arguments example using Function | |
def ed(arg1): | |
if arg1 == True: | |
print "decide1" | |
def real_d(f): | |
def rfunc(*args, **kwargs): | |
print "1", arg1 | |
print args | |
print kwargs | |
f(args, kwargs) |
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 random | |
import math | |
import time | |
NUMBER_OF_SIMULATIONS = 1000 | |
import math | |
def lognormal_mean(mu, sigma): | |
sigma_s = sigma * sigma | |
mu_s = mu * mu |
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 | |
AU_METER = 1.49597870691e11 #MS | |
AU_KM = 1.49597870691e8 | |
SEC = 1 | |
MIN = SEC * 60 | |
HOUR = MIN * 60 | |
DAY = 24 * HOUR | |
YEAR = DAY * 365 | |
G = 6.673e-11 |
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
print_seq(n, k): | |
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 _get_exposed_methods(self): | |
""" | |
Returns list of all the exposed method in the current controller. | |
""" | |
# | |
# TG controller class has _is_exposed method with same implementation but | |
# that method is private so we are not using it. One could say why we are | |
# not using the private method inside the class itself. That is because we |
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 random | |
square_arm = 10000 | |
radius = 50000 | |
points_in_circle = [] | |
import random | |
no_of_simulation = 1000000 | |
counter = 0 | |
random.seed(5000) | |
x_series = [] | |
while (counter < no_of_simulation): |
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
public class AbstractPosition {} | |
protected class ChessPiece { | |
enum color | |
enum player | |
// not really needed | |
is_alive | |
protected boolean is_valid_move(int x1, int y1, int x2, int y2); | |
} |
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
""" | |
Simple python programme to do monte carlo simulation, calculate var and plot histogram given simple python equation. | |
Usage: | |
python mc_simulation_helper.py < sample_input.txt | |
Sample Input File: | |
a + 10 | |
10000 |
NewerOlder