Skip to content

Instantly share code, notes, and snippets.

-- to use, type the following in the commandline: runhaskell tests.hs
expect :: (Eq a, Show a, Monad m) => a -> a -> m ()
expect a b = do
if a == b then
return ()
else
fail ("Expected " ++ (show a) ++ " but got " ++ (show b) ++ " instead.")
main = do
expect :: (Eq a, Show a, Monad m) => a -> a -> m ()
expect a b = do
if a == b then
return ()
else
fail ("Expected " ++ (show a) ++ " but got " ++ (show b) ++ " instead.")
run_tests = do
expect 1 1
expect 1 2
table = {0: 0, 1: 1}
def fib(n):
if n not in table:
table[n] = fib(n - 1) + fib(n - 2)
return table[n]
phi = 1.618033988749895
psi = 1 - phi
def binet(n):
phi_n = pow(phi,n)
Maxima(P1...Pn)
if n=1: return <p1>
A = {a1...aj} = Maxima(p1...pn/2)
S = {s1...sk} = Maxima(pn/2...pn)
i = 1
while ai > s1.y and i < j, do: i += 1
return {a1...a(i-1)} + {s1...sk}
public class Untitled {
public static void main(String[] params){
Life life = new Life();
String[][] list = life.readGame();
life.print(list);
System.out.println();
for(int i = 1; i <= 5; i++){
list = life.run(list);
from itertools import combinations
# in is the number of dimensions of the cube (3 for a 3d cube)
def generate_vertices(n):
for number_of_ones in xrange(0, n + 1):
for location_of_ones in combinations(xrange(0,n), number_of_ones):
location_of_ones = set(location_of_ones)
yield [1 if i in location_of_ones else 0 for i in xrange(0, n) ]
for vertex in generate_vertices(3):
input: .test--aSdF!
output:
.etst--SFad!
.estt--dFSa!
.estt--FaSd!
.stet--dFaS!
.etts--dFSa!
.tets--FaSd!
.stte--dSaF!
.tets--FadS!
import re
from itertools import *
string = raw_input()
parts = re.split('([^a-zA-Z]+)', string)
alpha_parts = [part for part in parts if re.match("[a-zA-Z]+",part)]
perms = permutations(apply(chain,alpha_parts))
import re
# input is a list of tokens (token is a number or operator)
tokens = raw_input()
# remove whitespace
tokens = re.sub('\s+', '', tokens)
# split by addition/subtraction operators
tokens = re.split('(-|\+)', tokens)
package recursionwachs;
public class Main {
// runs in O(n). Accesses ruler array elements contiguously for optimal speed
public static void computeTicksIterative(int[] ruler) {
for (int i = 0; i < ruler.length-1; i++) {
ruler[i] = bitToI[Integer.lowestOneBit(i)%37];
}
}