Skip to content

Instantly share code, notes, and snippets.

import Data.Monoid
import Data.List
import Control.Applicative
import Control.Monad
import Control.Monad.State
for :: [a] -> (a -> b) -> [b]
for = flip map
data Process i o a = Process {
line :: Proc String -- same as getLine
solveB :: Proc String
solveB = do
[nS,vS,xS] <- words <$> line
let
n = read nS :: Int
[v,x] = map read [vS,xS] :: [Double]
ss <- map (map read . words) <$> replicateM n line
let
@phi16
phi16 / Type.js
Last active August 29, 2015 14:24
Type
var Type = (function(){
var t = {};
function product(a,b){
var arr = [];
for(var i=0;i<a.length;i++){
for(var j=0;j<b.length;j++){
arr.push(a[i]+b[j]);
}
}
return arr;
@phi16
phi16 / Handler.js
Last active August 29, 2015 14:24
State Transition
var W = World(function(transit){
var Title;
var Game;
Title = function(){
var h = {};
var x = 0;
Input.listen(function(c){
if(c == Key.Enter)transit(Game(x));
@phi16
phi16 / lam.cpp
Last active February 5, 2016 17:26
Compile-time lambda calculus calculation http://ideone.com/us66y
#include<iostream>
#include<typeinfo>
#include<cxxabi.h>
template<int N> struct V{};
template<int N,class T> struct args{};
template<int M,int N> struct Var{};
template<bool N,class T> struct either{};
struct nu{};
template<class R,class T> struct lambda;
#include<iostream>
struct Status{
int buf[256];
int pos;
Status():pos(0){}
Status add(){
buf[pos]++;
return *this;
}
@phi16
phi16 / closure.js
Last active February 21, 2016 13:54
Closure Sample
// ------------------------------------------------------------------
// Usual Version
// ------------------------------------------------------------------
var i = 0;
var draw = function(xs){
console.log("Draw",i,":",xs);
i++;
};
var Mesh = function(v){
@phi16
phi16 / test.js
Created March 11, 2016 09:12
Entangled function
var e = (()=>{
var c = 0;
return {
a : ()=>c,
b : (x)=>{c=x;}
};
})();
var a = e.a;
var b = e.b;
console.log(a()); // => 0
@phi16
phi16 / a.hs
Created April 16, 2016 03:38
GCJ2016-1A
import Data.Monoid
import Data.List
import Data.Array
import Data.PriorityQueue.FingerTree
import Control.Lens
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Math.NumberTheory.Primes
@phi16
phi16 / bf.hs
Last active May 5, 2016 14:42
Brainf*ck interpreter
{-# LANGUAGE TupleSections #-}
import Control.Applicative
import Control.Arrow
import Control.Lens hiding (Empty)
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.State.Lazy hiding (State)
import Data.Char
import Data.Monoid