Skip to content

Instantly share code, notes, and snippets.

@thedeemon
thedeemon / gist:5736269
Last active December 18, 2015 05:58
thedeemon's June FP(FP) contest entry
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.Map as Map
import qualified Data.Set as Set
type Var = Char
sets :: [[Var]]
sets = [ ['i', 'R', 'T', 'r'],
import std.stdio, std.net.curl, std.algorithm, std.range, std.array, std.string, std.typecons, std.conv, std.math;
enum choco_xml = "choco.xml";
struct TagReader {
string data, start, end, cur;
bool empty() { return data is null; }
string front() { return cur; }
TagReader popFront()
{
if (findSkip(data, start)) {
@thedeemon
thedeemon / primeSpirals.d
Created January 7, 2014 05:49
Direct translation of github.com/ttsiodras/PrimeSpirals into D.
module main;
import std.stdio, std.range, std.algorithm, std.conv, std.typecons, std.math;
auto primeSpiralPixels()
{
auto primesSoFar = [2];
int color(int x) {
foreach(prime; primesSoFar.until!(p => p > sqrt(cast(float)x)))
if (0 == x % prime) return 255;
primesSoFar ~= x;
#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