Skip to content

Instantly share code, notes, and snippets.

@loosechainsaw
loosechainsaw / tddstack.cs
Created March 28, 2013 15:26
TDD Immutable Stack After Roy Osherove Master Class Yes I know the Size property is in 0(n) time currently.
namespace ImmutableDatastructures
{
public interface IImmutableStack<T>{
IImmutableStack<T> Push(T value);
IImmutableStack<T> Pop();
T Head{get;}
IImmutableStack<T> Tail{ get;}
int Size{get;}
bool IsEmpty();
@loosechainsaw
loosechainsaw / perfect-squares-tri.rkt
Created August 7, 2013 10:27
Using triangles to calculate perfect squares in Racket
#lang racket
(define (get-triangle row)
(cond
( ( = row 0) 0)
( ( = row 1) 1)
( else (+ row (get-triangle (sub1 row)) ))))
(define (nth-perfect-square count)
(cond
@loosechainsaw
loosechainsaw / memoise.cs
Last active December 21, 2015 01:38
Proof of concept Memoization support for C# - With Expiration
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
public interface IMemoizationPolicy
{
@loosechainsaw
loosechainsaw / cscurry.cs
Last active December 21, 2015 02:58
CSharp Curry
using System;
namespace ConsoleApplication1
{
public static class FunctionalExtensions
{
public static Func<TResult> Curry<TArg1, TResult>(this Func<TArg1, TResult> func, TArg1 arg1)
@loosechainsaw
loosechainsaw / qfind.cpp
Created August 17, 2013 10:38
Quick Find Algorithm and DataStructure
#include <iostream>
template<int N>
class quick_find{
public:
quick_find()
{
for(int i =0; i < N; ++i){
elements[i] = i;
}
@loosechainsaw
loosechainsaw / qunion.cpp
Created August 17, 2013 14:23
Quick Union In C++ From Robert Sedgewicks Algorithms Part 1 Course
#include <iostream>
template<int N>
class quick_union{
public:
quick_union()
{
for(int i =0; i < N; ++i){
elements[i] = i;
}
@loosechainsaw
loosechainsaw / qunionimproved.cpp
Last active December 21, 2015 05:59
Quick Union Weighted
#include <iostream>
template<int N>
class quick_union{
public:
quick_union()
{
for(int i =0; i < N; ++i){
elements[i] = i;
sizes[i] = 1;
@loosechainsaw
loosechainsaw / threesumquadraric.cpp
Created August 19, 2013 11:17
Quadratic slow 3 Sum Problem
#include <iostream>
template<class T>
T three_sum(T values[], int N){
T count = T();
for(int i = 0; i < N; ++i)
{
@loosechainsaw
loosechainsaw / twostack.cpp
Created August 21, 2013 13:07
Dijkstra Two Stack Solution
#include <iostream>
#include <stack>
#include <stdexcept>
#include <cctype>
#include <cstdlib>
using namespace std;
int evaluate(string const &expression){
stack<char> operators;
@loosechainsaw
loosechainsaw / synergy.cs
Created October 4, 2013 05:42
Functional Object Oriented Synergy In C#
using System;
namespace Synergy
{
public class Unit
{
public static Unit Empty()
{
return new Unit();