Skip to content

Instantly share code, notes, and snippets.

def PowerSet(base):
power_set = []
b = len(base)
map(lambda g: power_set.append(map(lambda x: base[x],
filter(lambda x: g[x], range(0, b)))),
map(lambda value: map(lambda x: (value >> x) & 1, range(b - 1, -1, -1)),
map(lambda value: value ^ (value / 2), range(0, 2**b))))
return power_set
print PowerSet([1,2,3])
import math
res_val = 19872
approx_list = []
parallel = lambda r1, r2: float(r1 * r2) / float(r1 + r2)
for sig in range(0, 4):
if len(approx_list) > 0:
pass
else:
#Sieve of Eratosthenes
def GetPrimes(p, i=1):
if i**2 < p[-1]:
p[i:] = filter(lambda x: x % p[i-1] != 0, p[i:])
return GetPrimes(p, i + 1)
return p
print GetPrimes(range(2,51))
#[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
import math
def PhiFrac(i): # 25 iterations will produce 10 digits of precision
if (i >= 0):
return 1.0 + (1.0 / phi_frac(i - 1))
return 1.0
def PhiSqrt(i): # 25 iterations will produce 10 digits of precision
if (i >= 0):
return math.sqrt(1.0 + phi_sqrt(i - 1))
@bemasher
bemasher / nimblegen_comp.py
Created August 11, 2009 03:41
Compares a list of chromosome regions from one file to a list of probes generated for NimbleGen.
"""Compares a list of chromosome regions from one file to a list of probes generated for NimbleGen."""
from optparse import OptionParser
import math
parser = OptionParser()
parser.usage = "%prog file1 file2 [options]"
parser.add_option("-r", "--range", type="int", dest="range", metavar="INT", default="200", help="set range tolerance [default: %default]")
parser.add_option("-p", "--percentage", action="store_true", help="display percentage of range covered instead of difference")
import random
import math
def moveBlank(boardValue, row, col):
temp = boardValue[row * 3 + col]
boardValue = boardValue.replace('9', ' ')
boardValue = boardValue.replace(temp, '9')
boardValue = boardValue.replace(' ', temp)
return boardValue
import sqlite3, re, math, os
con = sqlite3.connect(':memory:')
db = con.cursor()
contigs = [390,389,166,690,6907,6993,2656,3501,6990,1530,7291,7069,7277,7290,6922,7257,7126,1500,7214]
# Set filename and open input
in_file = open("trimmed.ace", "r")
import os
x264opts = ["b-adapt=2",
"rc-lookahead=50",
"ref=6",
"bframes=6",
"direct=spatial",
"b-pyramid=1",
"me=umh",
"merange=24",
/**
* Course: CSC345
* Due Date: 2009-10-07 23:59
*
* Purpose: Implement a B-tree as well as a range and fast range function.
*
* Not Implemented: I was only able to implement insert and in order traversal.
*/
import java.util.Arrays;
@bemasher
bemasher / EightPuzzle.java
Created August 6, 2010 03:47
Given an 8-Puzzle which is essentially a jig-saw puzzle with numbers instead of images this program is meant to solve them using a tree. Starting with the initial puzzle state as the root of a tree each possible move is added to the tree as a child and tr
import java.util.LinkedList;
import java.util.Queue;
import java.util.SortedMap;
import java.util.TreeMap;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;