Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Jachimiak davejachimiak

View GitHub Profile
@davejachimiak
davejachimiak / count-change.hs
Created Oct 3, 2014
tree-recursive solution to the counting change problem, pg. 41 SICP
View count-change.hs
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
View sicp-1.1.hs
-- 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)
View sicp-1.12.hs
-- 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
-- ...
View evented.js
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;
@davejachimiak
davejachimiak / sicp1.17.hs
Created Oct 25, 2014
sicp 1.17 in haskell
View sicp1.17.hs
-- ...
-- ...
-- [Assume your language doesn't have a multiplication function or
-- table. Given `double` and `half` functions,] design a
-- multiplication procedure that uses a logarithmic number of steps.
double :: Integer -> Integer
double x = x + x
halve :: Integer -> Integer
View sicp-1.18.hs
-- [Design an *iterative* process for multiplying to integers that] uses a
-- logarithmic number of steps.
double :: Integer -> Integer
double x = x + x
halve :: Integer -> Integer
halve x = x `div` 2
multiply :: Integer -> Integer -> Integer
@davejachimiak
davejachimiak / Makefile
Created Aug 8, 2015
A lispy arithmetic REPL
View Makefile
all:
/usr/local/Cellar/bison/3.0.4/bin/bison lispcalc.y && gcc -lm -o lispcalc lispcalc.tab.c
@davejachimiak
davejachimiak / inclusion.rb
Created Jun 9, 2012
:inclusion validator
View inclusion.rb
class Resource < ActiveRecord::Base
module Types
ACTIVE = 'active'
CANCELLED = 'cancelled'
CEASED = 'ceased'
DITCHED = 'ditched'
MEDIA = 'media'
ONE_TIME = 'one time'
ARCHIVED = 'archived'
end
View create_cohabitants_notifications.rb
class CreateCohabitantsNotifications < ActiveRecord::Migration
def change
create_table :cohabitants_notifications, :id => false do |t|
t.string :cohabitant_id, :null => false
t.string :notification_id, :null => false
end
end
end
View create_cohabitants_notifications.rb
class CreateCohabitantsNotifications < ActiveRecord::Migration
def change
create_join_table :cohabitants, :notifications
end
end
You can’t perform that action at this time.