Skip to content

Instantly share code, notes, and snippets.

View MichaelBurge's full-sized avatar

Michael MichaelBurge

View GitHub Profile
@MichaelBurge
MichaelBurge / gist:3de86bc227bff32ac9d15b162c6c6da7
Created June 19, 2018 17:09
StackLisp implementation of Pyramid runtime
#lang sweet-exp stacklisp
provide
rename-out void identity
define-variable!
set-variable-value!
lookup-variable-value
extend-environment
tag
rename-out allocate-words allocate
@MichaelBurge
MichaelBurge / fitpoly.hs
Created March 21, 2018 04:16
First Haskell I ever wrote
import System( getArgs )
import System.Console.GetOpt
import System.IO
import Ratio
import Numeric
{- Returns the binomial coefficient. -}
binomial m 0 = 1
binomial 0 n = 0
binomial (m+1) (n+1) = (binomial m n) * (m+1) `div` (n+1)
@MichaelBurge
MichaelBurge / gist:237217e3151f2788f3c04c1c5ded4f4c
Created March 21, 2018 04:04
Old "enterprise" integer operations in C++
#include <iostream>
#include <deque>
#include <functional>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
union Integer;
@MichaelBurge
MichaelBurge / gist:1cc8e45ac021729c133fd42155a6284f
Created September 15, 2017 09:09
Haskell -- diff anything
import System.IO.Temp
import System.IO.Unsafe
import System.Process
import Data.Text
debugDiffIO :: Show a => a -> a -> IO (Maybe Text)
debugDiffIO x y = do
xf <- writeSystemTempFile "x" $ show x
yf <- writeSystemTempFile "y" $ show y
(exitCode, result, _) <- readProcessWithExitCode "git" ["diff", "--no-index", "--color-words=.", xf, yf] ""
f x = if even x then x `div` 2 else reduce (3 * x + 1) where reduce x | even x = reduce $ x `div` 2 ; reduce x = x
until (\x -> f x == x) f 19
1