Skip to content

Instantly share code, notes, and snippets.

View davejachimiak's full-sized avatar

Dave Jachimiak davejachimiak

View GitHub Profile
var Evented;
Evented = {
on: function(event, callback) {
var _base;
(_base = this.callbacks)[event] || (_base[event] = []);
return this.callbacks[event].push(callback);
},
trigger: function(event) {
var args, callbacks;
-- SICP 1.12
--
-- The following pattern of numbers is called Pascal's triangle.
--
-- 1
-- 1 1
-- 1 2 1
-- 1 3 3 1
-- 1 4 6 4 1
-- ...
@davejachimiak
davejachimiak / sicp-1.1.hs
Last active August 29, 2015 14:07
SICP 1.11
-- SICP 1.11
--
-- A function f is defined by the rule that f(n) = n if n < 3 and
-- f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n >= 3. Write a
-- procedure computes f by means of a recursive process.
--
f :: Integer -> Integer
f n
| n < 3 = n
| otherwise = f (n - 1) + 2 * f (n - 2) + 3 * f (n - 3)
@davejachimiak
davejachimiak / count-change.hs
Created October 3, 2014 00:05
tree-recursive solution to the counting change problem, pg. 41 SICP
countChange :: Integer -> [Integer] -> Integer
countChange amount denominations
| null denominations || amount < 0 = 0
| amount == 0 = 1
| otherwise = countChange amount (tail denominations) + countChange (amount - head denominations) denominations