Skip to content

Instantly share code, notes, and snippets.

@ddrone
ddrone / rmq.kt
Created October 19, 2013 11:55
RMQ tree
package rmq
import java.util.ArrayList
import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.StringTokenizer
trait RMQTree {
fun getMinimum(from: Int, to: Int): Int
}
@ddrone
ddrone / Imp.agda
Created October 5, 2013 14:30
Innovative representation of IMP programming language
module Imp where
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
data Vec (A : Set) : ℕ → Set where
[] : Vec A Z
_∷_ : ∀ {n} → A → Vec A n → Vec A (S n)
@ddrone
ddrone / Trees.hs
Created September 1, 2013 14:46
Trees generation in Java and Haskell
{-# LANGUAGE TupleSections #-}
module Trees where
data Tree = Leaf
| Branch2 Tree Tree
| Branch3 Tree Tree Tree
deriving (Show, Eq)
size :: Tree -> Int
module Tree where
data Expr = Digit Int
| Complex Expr Expr Expr
deriving (Show)
generateAll :: Int -> [Expr]
generateAll 1 = [Digit 0, Digit 1]
generateAll n | n <= 0 = []
generateAll n = do
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class ProxyTest {
private static interface CatInterface {
public CatInterface printName();
@ddrone
ddrone / test.cpp
Created April 1, 2013 19:59
Operator overriding in C++
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
virtual void operator-(const A& other) const;
};
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Gauss {
public static void swapRows(double[][] a, double[] b, int i, int j) {
double[] row = a[i];
@ddrone
ddrone / Test.hs
Created February 20, 2013 04:24
Syntactically valid Haskell!
square, double :: Int -> Int
square x = x * x
double x = x * 2
module RecursiveExplicit where
import Prelude hiding (sum)
import Data.Char (isDigit)
type Stack = [(Integer, Char)]
readInt :: String -> Integer
readInt = read