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
from math import * | |
a = 1.5830872612179103E+00 | |
b = 7.3465267498264183E+01 | |
c = -3.0305229706863263E-01 | |
d = 7.3692380600745080E-03 | |
f = 4.2772859170011763E-07 | |
j = 1.4850479626806965E+01 | |
k = -1.6117222974925229E+00 | |
stretch = lambda N, R: c + log(N+b)*a +f*N + d*R + k*log(R+j) |
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
% xelatex conditional | |
\newif\ifxelatex | |
\ifx\XeTeXglyph\undefined | |
\xelatexfalse | |
\else | |
\xelatextrue | |
\fi | |
% Me tahame kirjutada eesti keeles ja kasutada ka mitteameerikalikke tähti | |
\ifxelatex |
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 <cstdio> | |
typedef long long int lld; | |
typedef long long unsigned int llu; | |
lld gcd(lld a, lld b) { | |
lld temp; | |
if (b > a) { | |
// swap | |
temp = a; |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def possibilities(items, length): | |
items = tuple(items) | |
if length < 1: | |
yield [] | |
else: | |
for others in possibilities(items,length-1): | |
for item in items: |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# 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 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
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
def cyclicmask(A,B,(ki,kj)=(0,0)): | |
"""" | |
Applies a mask B to A, centering at (ki,kj) and wrapping around the edges. | |
"""" | |
lAx = len(A) | |
lA = [len(A[i]) for i in range(lAx)] | |
return [[ # each element in the result is | |
sum( # over di | |
sum( # over dj | |
A[(i+ki+di) %lAx][(j+kj+dj) % lA[i]]*B[di][dj] |
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> | |
#include <string.h> | |
#include <stdbool.h> | |
#include <malloc.h> | |
// input file is named pusle.sis and on the first row there should be | |
// dimensions of the puzzle, then all tiles should follow (separated by whitespace) | |
// Example: | |
// 2 3 | |
// 1 2 3 |
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 os, glob | |
import cPickle as pickle | |
class QueueDir: | |
def __init__(self,dir,pattern='*',statefilename='.queuedir.pc'): | |
self.statefilename = statefilename | |
self.pattern = pattern | |
self.dir = dir | |
self.file_in_progress_mtime = None |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from functools import wraps | |
try: | |
import cPickle as pickle | |
except: | |
import pickle | |
def cached(fn): | |
cache = {} |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import random | |
def itershuffle(iterable,bufsize=1000): | |
"""Shuffle an iterator. This works by holding `bufsize` items back | |
and yielding them sometime later. This is NOT 100% random, proved or anything.""" | |
iterable = iter(iterable) | |
buf = [] |