This file contains 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
/** | |
* Fast computations of cumulative sums. | |
* D. Lemire, July 2012 | |
* | |
* Best results with: | |
* | |
$ g++-4.7 -funroll-loops -O3 -o cumulsum cumulsum.cpp | |
$ ./unrolldeltas |
This file contains 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
set autoindent | |
set smartindent | |
set tabstop=4 | |
set shiftwidth=4 | |
set expandtab | |
set softtabstop=4 | |
set showmatch |
This file contains 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 glob | |
from os.path import basename, splitext | |
ls = [l.strip() for l in open('_winnie.txt').read().splitlines() if l.strip()] | |
my_f = set(l[2:] for l in ls if l[0] != '#' and l[0] == '>') | |
my_f.remove('_winnie') | |
print 'digraph {' |
This file contains 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
#include <stdio.h> | |
struct Point2f { | |
float x, y; | |
Point2f(float _x, float _y): x(_x), y(_y) {} | |
Point2f(): x(0), y(0) {} | |
}; | |
Point2f operator -(Point2f p1, Point2f p2) { |
This file contains 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
# minimal tree cost built from list, problem from http://antilamer.livejournal.com/431230.html | |
# cost of tree is sum(depth(i)*value(i)) | |
list = [1,2,3,4,5,7,6,5,4,3,2,10000] | |
n = len(list) | |
#table from (start, length) to (cost, x-sum, root) for best tree on segment (start, length) | |
table_start_l = [[(0,0,-1000)]*(n-start+1) for start in xrange(n+1)] |
This file contains 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
# Ivan Dobrokotov, dobrokot 'at' gmail.com | |
def calc_moves(x, y): | |
result = [] | |
for dx, dy in [(1, 2), (2, 1), (-1, 2), (-2, 1), (-1, -2), (-2, -1), (1, -2), (2, -1)]: | |
nx, ny = (x + dx, y+dy) | |
if 0 <= nx < 8 and 0 <= ny < 8: | |
result.append((nx, ny)) | |
return result | |
This file contains 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 re | |
def f1(c): | |
return c in ''' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\\'()*-.:<>[]^`{|}~''' | |
ALLOWED = re.compile('''[ a-zA-Z0-9!"'()*.:<>^`{|}~\\\[\]-]''') | |
def f2(c): | |
return bool(re.match(ALLOWED, c)) | |
This file contains 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
#include <boost/shared_ptr.hpp> | |
#include <iostream> | |
struct T { | |
boost::shared_ptr<MayBe<T> > next; | |
int i; | |
T() { i = 10; } | |
}; |
This file contains 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
#include "may_be.hpp" | |
#include <iostream> | |
struct Point { //тип, над которым мы будем эксперементировать. | |
float x, y; | |
Point(float x, float y): x(x), y(y) {} | |
Point(): x(0), y(0) {} | |
}; |
This file contains 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
#include "may_be.hpp" | |
#include <iostream> | |
struct Point { //тип, над которым мы будем эксперементировать. | |
float x, y; | |
Point(float x, float y): x(x), y(y) {} | |
Point(): x(0), y(0) {} | |
}; |