Skip to content

Instantly share code, notes, and snippets.

@majiang
majiang / sc.ini
Created August 27, 2017 06:31
C:/D/dmd2/windows/bin/sc.ini generated by installing DMD 2.075.1 after Visual Studio 2017 Community on Windows 10
[Version]
version=7.51 Build 020
; environment for both 32/64 bit
[Environment]
DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import"
; optlink only reads from the Environment section so we need this redundancy
; from the Environment32 section (bugzilla 11302)
@majiang
majiang / d-man.svg
Created December 17, 2015 13:47
The cutest mascot of a programming language.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import std.functional : binaryFun;
debug import std.stdio;
unittest ///
{
auto heystack = [1, 1, 3, 3, 3, 3, 5, 5];
assert (heystack.infEqual(0) == heystack.length);
assert (heystack.infEqual(2) == heystack.length);
assert (heystack.infEqual(4) == heystack.length);
assert (heystack.infEqual(6) == heystack.length);
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
void main()
{
foreach (m; 0..readln().chomp().to!int())
{
bool[string] ans;
@majiang
majiang / choose.d
Created November 10, 2014 13:08
A function which receives the index and lazy arguments, and returns one of the arguments at the index.
import std.stdio;
/// won't compile.
auto choose(T)(size_t i, lazy T[] choice...)
{
return choice[i];
}
/// to be generalized.
auto choose(T)(size_t i, lazy T c0, lazy T c1)
def bs(f, x=0.0, y=1.0, eps=0.001):
if f(y) < 0:
return bs(f, y, 3*y-x, eps)
if 0 < f(x):
return bs(f, 3*x-y, x, eps)
m = (x + y) / 2
if y - x < eps:
return m
if f(m) < 0:
return bs(f, m, y, eps)
@majiang
majiang / fan.txt
Created June 10, 2014 06:31
guobiao majiang fan
大四喜 dà sì xǐ
大三元 dà sān yuán
绿一色 lǜ yí sè
九莲宝灯 jiŭ lián bǎo dēng
四杠 sì gàng
连七对 lián qī duì
十三幺 shí sān yāo
清幺九 qīng yāo jiŭ
小四喜 xiǎo sì xǐ
小三元 xiǎo sān yuán
import std.stdio;
import std.datetime : Date;
import std.string : strip;
import std.array : split, empty, front, popFront, array;
import std.conv : to;
import std.algorithm : map, sort, swap;
void main()
{
auto buf = stdin.byLine().map!toInterval().array();
___ 120 103 130 201 301 031 012 310 013 101 011 110
120 ___ 113 ___ 111 331 331 111 ___ 113 112 112 ___
103 113 ___ 133 ___ ___ 123 133 312 113 ___ 312 123
130 ___ 133 ___ 131 321 131 133 ___ 132 132 321 ___
201 111 ___ 131 ___ ___ 131 111 313 313 ___ 121 121
301 331 ___ 321 ___ ___ 331 311 311 213 ___ 321 213
031 331 123 131 131 331 ___ ___ 231 ___ 231 ___ 123
012 111 133 133 111 311 ___ ___ 311 ___ 211 ___ 211
310 ___ 312 ___ 313 311 231 311 ___ 313 231 312 ___
013 113 113 132 313 213 ___ ___ 313 ___ 132 ___ 213
@majiang
majiang / chiba.tsv
Last active January 2, 2016 05:28
My JMSA Results
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 5 columns, instead of 13. in line 1.
Year Month Rank #Player Score
2009 06 5 16 +157 -103 -60 +65 +60 +184 +60 -29 -20
2009 07 0 12
2009 08 6 16 -2 -15 +20 -88 -20 +80 +20 -19 +20
2009 09 0 16
2009 10 0 12
2009 11 5 16 +147 +47 +20 -2 +20 +111 +60 -89 -20
2009 12 10 20 +44 -22 +20 -46 -20 +91 +60 -19 -20
2010 01 0 16
2010 02 0 16