Skip to content

Instantly share code, notes, and snippets.

#include "stdafx.h"
#include <vector>
#include <stdio.h>
#include <atlcoll.h>
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> data;
data.resize(10000000);
FILE *f = fopen("ints.dat", "rb");
void readAndMeasure(K)(size_t num, string fname) {
auto data = cast(K[]) std.file.read(fname);
enforce(data.length == num);
auto h = new RHHash!(K,int);
measure("# " ~ typeof(h).stringof ~ ".make_histo", (){
foreach(x; data)
h[x]++;
});
measure("# " ~ typeof(h).stringof ~ ".read_histo", (){
int v = 0;
using System;
using System.Collections.Generic;
using System.Text;
namespace mangolian
{
struct Pair<A, B>
{
public A fst;
public B snd;
@thedeemon
thedeemon / gist:44b33b07380ff4cb5fa2
Created August 9, 2014 12:10
Aug'14 FP(FP) contest entry of thedeemon
module main;
import std.stdio, std.range, std.algorithm, std.string, std.typecons;
enum W = 3;
enum H = 5;
char[W][H][10] symbols = [["111", "101", "101", "101", "111"], ["110", "010", "010", "010", "111"],
["111", "001", "111", "100", "111"], ["111", "001", "111", "001", "111"], ["101", "101", "111", "001", "001"],
["111", "100", "111", "001", "111"], ["111", "100", "111", "101", "111"], ["111", "001", "011", "010", "010"],
["111", "101", "111", "101", "111"], ["111", "101", "111", "001", "111"]];
line: 1 col: 1 digit: 0
line: 1 col: 5 digit: 1
line: 1 col: 9 digit: 2
line: 1 col: 13 digit: 3
line: 1 col: 17 digit: 4
line: 1 col: 21 digit: 5
line: 1 col: 25 digit: 6
line: 1 col: 29 digit: 7
line: 1 col: 33 digit: 8
line: 1 col: 37 digit: 9
@thedeemon
thedeemon / gist:ffd1509a7b1ce77af8a4
Created August 10, 2014 04:23
Aug'14 FP(FP) contest entry of thedeemon, shorter version
module main;
import std.stdio, std.range, std.algorithm, std.string, std.typecons;
enum W = 3;
enum H = 5;
char[W][H][10] symbols = [["111", "101", "101", "101", "111"], ["110", "010", "010", "010", "111"],
["111", "001", "111", "100", "111"], ["111", "001", "111", "001", "111"], ["101", "101", "111", "001", "001"],
["111", "100", "111", "001", "111"], ["111", "100", "111", "101", "111"], ["111", "001", "011", "010", "010"],
["111", "101", "111", "101", "111"], ["111", "101", "111", "001", "111"]];
@thedeemon
thedeemon / gist:d9dfe4982ab6c5e68854
Created January 5, 2015 17:03
micro interpreter in Haskell
import Data.List
import Control.Monad.ST
import Control.Monad
import Data.Array.ST
import Data.Array.Unboxed
data Exp = IfGt Int Int Block Block -- if a[i] > a[j] then blk1 else blk2
| Swap Int Int -- a[i] <-> a[j] (i,j < 8)
| Copy Int Int -- a[i] <- a[j] (i > 7)
deriving Show
@thedeemon
thedeemon / gist:b6dcfef0d74227c698b1
Last active August 29, 2015 14:12
micro interpreter in OCaml
type exp = IfGt of int * int * block * block
| Swap of int * int
| Copy of int * int
and block = exp list;;
let rec eval a = function
| IfGt(i, j, b1, b2) ->
let (r,n) = evalBlock a (if a.(i) > a.(j) then b1 else b2) in
(r, n+1)
| Swap(i, j) ->
@thedeemon
thedeemon / gist:b3969f49df0cbc6eb376
Created January 5, 2015 17:07
Micro interpreter in D
import std.stdio, std.algorithm;
struct Exp {
enum Tag { IfGt, Swap, Copy }
Tag tag;
int i, j;
Exp[] bl1, bl2;
}
int eval(int[] a, const ref Exp e) {
@thedeemon
thedeemon / gist:48ab320c3675916f3980
Created January 6, 2015 08:21
Micro interpreter in OCaml, simplified
type exp = IfGt of int * int * block * block
| Swap of int * int
| Copy of int * int
and block = exp list;;
let rec eval a = function
| IfGt(i, j, b1, b2) ->
1 + evalBlock a (if a.(i) > a.(j) then b1 else b2)
| Swap(i, j) ->
let ai = a.(i) and aj = a.(j) in