Skip to content

Instantly share code, notes, and snippets.

@irtaylor
irtaylor / dynamic_fib.cpp
Last active December 3, 2017 03:32
a c++ performance test for dynamic programming fibonacci calculations vs naive recursive calculations
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <ctime>
using std::clock_t;
#include <map>
using std::map;
@irtaylor
irtaylor / dynamic_fib.rb
Last active November 30, 2017 14:01
dynamic programming fibonacci
# Dynamic Programming for calculating nth Fibonacci Number
# Ian Taylor, 2017
def dp_fib(n, memo={})
return memo[n] unless memo[n].nil?
(n <= 2) ? f = 1 : f = dp_fib(n - 1, memo) + dp_fib(n - 2, memo)
memo[n] = f
f
end
# standard recursive Fibonacci
@irtaylor
irtaylor / ycombinator.scm
Created November 20, 2017 14:08
implementation (from memory) of the applicative order Y combinator
; Applicative Order Y-Combinator
(define Y
(lambda (f)
((lambda (x) (x x))
(lambda (x) (f (lambda (y) ((x x) y)))))))
@irtaylor
irtaylor / graph.go
Last active October 26, 2017 23:08
Representing a Graph
package main
import (
"fmt"
"log"
)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
See See Cormen, et al, 3rd ed. page 592
@irtaylor
irtaylor / heapSort.go
Created October 24, 2017 13:37
heapsort in go
// Heapsort Go, Ian Taylor 2017
// A very simple heapsort,
// emphasizing algorithmic clarity over optimization
package main
import (
"fmt"
)
@irtaylor
irtaylor / quickSort.go
Last active September 29, 2017 19:47
implementation of quicksort algorithm in Go, using a randomized pivot. Emphasis on algorithmic clarity over optimization.
// Quicksort Go, Ian Taylor 2017
// A very simple quicksort implementation with a randomized pivot,
// emphasizing algorithmic clarity over optimization
package main
import (
"fmt"
"math/rand"
"time"
@irtaylor
irtaylor / binary_search.go
Created September 18, 2017 23:28
implementation of iterative and recursive binary search in Go
package main
import (
"fmt"
)
func binary_search_recursive(A []int, key, low int, high int) int {
if low > high {
return -1
}
@irtaylor
irtaylor / mergeSort.go
Last active September 14, 2017 15:31
merge sort in go
// Merge Sort Go, Ian Taylor 2017
// A very simple mergesort implementation, emphasizing algorithmic clarity over optimization
package main
import (
"fmt"
)
// sort an unsorted array in ascending order
@irtaylor
irtaylor / filterMapReduce.scm
Last active September 14, 2017 15:12
Scheme Implementation of the Filter-Map-Reduce pattern
; return a new list, where elements that do not
; meet the conditions of the filter function are removed
(define myfilter
(lambda (func lat)
(cond
((null? lat) (quote ()))
((func (car lat)) (cons (car lat)
(myfilter func (cdr lat))))
(else
(myfilter func (cdr lat))))))
@irtaylor
irtaylor / ncurses_menu.c
Last active January 16, 2017 02:19
A short demo of an ncurses menu.
// Code copied from Casual Coder's youtube ncurses demo:
// https://youtu.be/ucmigNoLPeg
#include <ncurses.h>
#include <string.h>
int main(){
/* NCURSES START */
initscr();