Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3.1
import sys;
import functools;
import operator;
import fractions;
def readAdjlist(file):
adjlist = []
with open(file) as f:
import Data.List
import System
-- Encode a character range as regex.
bs :: Char -> Char -> String
bs '0' '9' = "\\d"
bs 'A' y = bs '1' y
bs x y | y == x = [x]
| y == succ x = ['[', x, y, ']']
| True = ['[', x, '-', y, ']']
#include <cmath>
// Get gsl.hpp from http://code.google.com/p/igraphhpp/source/browse/trunk/gsl.
#include <gsl/gsl.hpp>
#include <ctime>
#include <algorithm>
#include <cstdio>
#include <tr1/unordered_map>
static const int N = 50;
static const int T = 150;
/*
ising.cpp ... Ising Model
Copyright (C) 2010 KennyTM~ <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
/*
vmc.cpp ... Variational Monte Carlo.
Copyright (C) 2010 KennyTM~ <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
#!/usr/bin/env python3.1
#
# multicoin.py ... Quantum walk with multiple biased coins
#
# Copyright (C) 2010 KennyTM~
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#!/usr/bin/env python3.1
import timeit
from itertools import chain
def magic(f): return f
def more_magic(f): return f
@magic
def double_digits_holger8(x):
#!/usr/bin/env python2.7
#
# parrondo_optimizer.py ... Parrondo's paradox which optimizes the sequence.
# Copyright (C) 2010 KennyTM~ <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#!/usr/bin/env python3.1
#
# x.py ... Classical Parrondo paradox.
#
# Copyright (C) 2010 KennyTM~
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@kennytm
kennytm / multiple_dispatch.d
Created April 25, 2011 14:12
Multiple dispatch in D
import std.traits, std.typetuple;
template GeneralizeType(T) {
static if (is(T == class))
alias Object GeneralizeType;
//@@@BUG@@@ Should preserve qualifier of T.
else
alias T GeneralizeType;
}
mixin template ImplementMultipleDispatch(alias method, alias Parent = __traits(parent, method)) {
private enum methodName = __traits(identifier, method);