Skip to content

Instantly share code, notes, and snippets.

View alphaKAI's full-sized avatar

Akihiro Shoji alphaKAI

View GitHub Profile
@alphaKAI
alphaKAI / ski.d
Last active September 11, 2016 07:46
The SKI combinator calculus in D's type system. Inspired by https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/
/*
The SKI combinator calculus in D's type system
Inspired by https://michid.wordpress.com/2010/01/29/scala-alias-level-encoding-of-the-ski-calculus/
*/
interface Term {
alias ap(X: Term) = Term;
alias eval = Term;
}
@alphaKAI
alphaKAI / logics.d
Last active September 11, 2016 06:20
Logics.(Problems and Answer, includes a template which judge the given logic express is a tautology)
// ¬P
bool not(bool p) {
return !p;
}
// P ∧Q
bool and(bool p, bool q) {
return p && q;
}
@alphaKAI
alphaKAI / hexr.d
Created September 5, 2016 08:36
Plain hexdump tool, like `hexdump -C` in D.
import std.range,
std.stdio,
std.file;
void main(string[] args) {
args = args[1..$];
if (!args.length) {
writeln("usage : ./hexr files...");
}
@alphaKAI
alphaKAI / nqueen.d
Created September 3, 2016 06:16
N-Queen Solver with backtracking in D
//N-Queen Solver with backtracking in D
import std.algorithm,
std.range,
std.stdio,
std.conv;
enum N = 8;
string rep(string ptn, size_t n) {
string ret;
@alphaKAI
alphaKAI / errors
Created August 24, 2016 06:48
When I try to compile a dcode, ld dumped these error (My Environment: ArchLinux x86_64, using latest DMD and libphobos-devel in arch's community repository.)
/usr/bin/ld: /usr/lib/libphobos2.a(exception_223_55a.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/libphobos2.a(exception_224_3b4.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/libphobos2.a(exception_227_4a2.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/libphobos2.a(exception_229_5cc.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/libphobos2.a(aApply_4d7_3be.o): relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/libphobos2.a(dmain2_626_47b.o): relocation R_X86_64_32 against symbol `_D6object9Thro
@alphaKAI
alphaKAI / minimalQueue.d
Created July 23, 2016 12:03
Minimal Stack&Queue data structure Implementation in D
/*
Minimal Queue data structure Implementation in D
Copyright (c) 2016 alphaKAI
This software is released under the MIT License.
*/
import core.memory;
struct Node(T) {
@alphaKAI
alphaKAI / assoc.d
Created July 15, 2016 10:48
The associative array that an order was guaranteed for D.
/**
* The associative array that an order was guaranteed.
*
* Whythis library was necessary:
* D's Associative Array has a (critical) trouble:
* int[string] foo = [
* "abc" : 123,
* "k" : 3874,
* "abcdef" : 0];
* foreach (key, value; foo) {
@alphaKAI
alphaKAI / ExprTree.d
Last active July 11, 2016 15:51
Expression Tree in D.
enum ExprType {
Number,
Add,
Sub,
Mul,
Div,
Variable
}
alias Environment = double[string];
@alphaKAI
alphaKAI / tinyBase64Encoder.fs
Last active June 29, 2016 23:15
Tiny Base64 Encoder in F#
module tinyBase64Encoder
open System
open System.Collections.Generic
// Declare fundamental functions
// Convert binary string into decimal
let binToDec binStr = Convert.ToInt32 (binStr, 2)
// Convert decimal into binary string
import std.algorithm,
std.string,
std.ascii,
std.range,
std.conv;
import std.stdio;
R delegate(Args) Z(R, Args...)(R delegate(R delegate(Args), Args) f){
return (Args args) => f(Z(f), args);
}