Skip to content

Instantly share code, notes, and snippets.

module Main where
import Data.List
import Data.Array
import Data.Char
s 0 = 0
s x = x `mod` 10 + s (x `div` 10)
b2r 0 = "0"
import Data.List
ev s = map (\x -> (x, elemIndices x s)) $ nub s
unifyAux [] [] substs = Just substs
unifyAux (x:xs) (y:ys) substs = if snd x == snd y then unifyAux xs ys ((fst x, fst y) : substs) else Nothing
unifyAux _ _ _ = Nothing
unify s1 s2 = unifyAux (ev s1) (ev s2) []
import Control.Monad
import Data.Char
import Data.List
makeGroup xs = (head xs, length xs)
histogram = map makeGroup . group . sort
diffHistograms ((lx, cx) : xs) ((ly, cy) : ys)
| lx == ly && cx == cy = diffHistograms xs ys
import Control.Arrow
import Control.Monad
import Data.Char
import Data.List
import System.Environment
histogram = map (head &&& length) . group . sort
diffHistograms ((lx, cx) : xs) ((ly, cy) : ys) acc
| lx == ly && cx == cy = diffHistograms xs ys acc
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
namespace AsyncTest
{
struct AsyncThread
{
public static void Start<T>(Func<AsyncCallback, T, IEnumerator> operation, T argument)
@lnicola
lnicola / phentropy.cpp
Created June 26, 2014 10:26
phentropy: Zalewskian Phase Space Entropy Viz for OpenQVIS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
void write_datfile(FILE *dat, char *datname, char *resolution);
unsigned int md(unsigned char x, unsigned char y, unsigned char z);
unsigned char plot_point(unsigned char *matrix, int density,
unsigned char x, unsigned char y, unsigned char z,
char shift);
using System.IO;
using System.Text;
namespace TeXify
{
class Program
{
static bool inQuotes = false;
static string FixLine(string line)
@lnicola
lnicola / Textile.cs
Created June 24, 2014 14:57
Textile test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Textile
{
static class ExtensionMethods
{
#include <algorithm>
#include <array>
#include <chrono>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
#include <mmintrin.h>
@lnicola
lnicola / MaxFlow.cs
Created June 24, 2014 14:36
Maximum flow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Tunnels
{
class Program
{