Skip to content

Instantly share code, notes, and snippets.

@majiang
majiang / fixe.d
Created November 10, 2013 01:12
Fixed point arithmetic
module fixed;
import std.traits : isSigned;
struct Fixed(BaseSigned, size_t digitsFraction)
if (isSigned!BaseSigned)
{
BaseSigned x;
Fixed opBinary(string op)(Fixed!(BaseSigned, digitsFraction) rhs) pure
if (op == "+" || op == "-" || op == "*" || op == "/")
module denko;
import std.stdio;
import std.typecons : Tuple, tuple;
alias Tuple!(uint, uint) Input;
alias tuple!(uint, uint) pair;
/** Find single letter. */
auto isLetter(Input input)
{
void main()
{
import std.algorithm, std.random, std.range, std.numeric;
auto obj = new Fft2D!Fft(4, 4); // FFT を提供するクラスのインスタンスは1つあれば十分な気がする (x, y でサイズが違っても大きい方を持ってよい)
double[][] input;
foreach (i; 0..4)
input ~= iota(0, 4).map!(b => uniform(0.0, 1.0))().array();
auto result = obj.fft!real(input);
auto inv = obj.inverseFft!real(result);
module genz;
import std.stdio;
import std.math;
/// simple exponential function: integral is (e-1)^s.
template exponential(size_t s)
{
double f(double[] x)
in
@majiang
majiang / downloader.d
Last active December 26, 2015 10:19 — forked from repeatedly/downloader.d
// Written in the D programming language.
/**
* High peformance downloader
*
* Implemented according to <a href="http://yusukebe.com/archives/20120229/072808.html">this implementation</a>.
*
* Example:
* -----
* dmd -L-lcurl -run downloader.d
@majiang
majiang / st.d
Created October 20, 2013 14:48
segment tree
/** Generic segment tree for monoids.
Segment tree is a data structure which stores Monoid elements x[], the number
of which, n, is fixed on initialization. Monoid is a set with an associative
binary operation and identity element.
The constructor has time complexity of O(n), takes n and initialize the tree
with n copies of identitiy, or takes the elements of initial array.
The tree has two operation both of which is done in Theta(lg n) time:
@majiang
majiang / uft.d
Last active December 26, 2015 01:19
union find tree
struct UF
{
ptrdiff_t[] parent;
size_t n;
this (size_t n)
{
parent.length = this.n = n;
foreach (i; 0..n)
parent[i] = -1;
}
@majiang
majiang / subsp.txt
Last active December 22, 2015 10:48
The number of linear subspaces over F_2
1
1 1
1 3 1
1 7 7 1
1 15 35 15 1
1 31 155 155 31 1
1 63 651 1395 651 63 1
1 127 2667 11811 11811 2667 127 1
1 255 10795 97155 200787 97155 10795 255 1
1 511 43435 788035 3309747 3309747 788035 43435 511 1
@majiang
majiang / ao.csv
Last active December 18, 2015 13:49
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 9 columns, instead of 14 in line 1.
1,0,1.516128073971352e+01,7.3599447962117581067415549,1038190921,1067664719,1022544248,,
2,1,7.297076628010927e+00,5.3290383948809241067415549,1038190921,1067664719,1022544248,,534925147,926819890,148510961,595243301,,
3,2,3.385686549234856e+00,5.4226540015158951067415549,1038190921,1067664719,1022544248,,534925147,926819890,148510961,595243301,,160557587,1014518717,889526877,45929852,,
4,2,1.434922621151101e+00,5.0618637568899321067415549,1038190921,1067664719,1022544248,,534925147,926819890,148510961,595243301,,160557587,1014518717,889526877,45929852,,518033346,496810539,498913765,499085382,,
5,2,6.073717484216554e-01,5.1328493465742831067415549,1038190921,1067664719,1022544248,,534925147,926819890,148510961,595243301,,160557587,1014518717,889526877,45929852,,518033346,496810539,498913765,499085382,,287067364,329790267,859615399,281371802,,
6,3,2.557584970678430e-01,5.1935677578078261067415549,1038190921,1067664719,1022544248,,534925147,926819890,148510961,595243301,,160557587,1014518717,889526877,45929852,
@majiang
majiang / biconc.d
Created June 1, 2013 02:16
concurrency for bisectable data structures
struct gray
{
size_t shifter;
immutable(size_t)[] basis;
size_t count;
invariant ()
{
assert (basis.length < size_t.sizeof << 3);
}
@property bool empty()