Skip to content

Instantly share code, notes, and snippets.

# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. The tests should fail if any part of the application breaks.
# For example: If "gets" is moved before "puts" then the tests should
# fail since that breaks the application.
#
# 2. You cannot change the Quiz class. But you can use whatever framework
# and tools you want for the tests. (RSpec, Cucumber, etc.)
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. The tests should fail if any part of the application breaks.
# For example: If "gets" is moved before "puts" then the tests should
# fail since that breaks the application.
#
# 2. You cannot change the Quiz class. But you can use whatever framework
# and tools you want for the tests. (RSpec, Cucumber, etc.)
;; Exercise 1.1. Below is a sequence of expressions. What is the
;; result printed by the interpreter in response to each expression?
;; Assume that the sequence is to be evaluated in the order in which
;; it is presented.
;; 10
;; => 10
;; (+ 5 3 4)
;; => 12
;; SICP 1.4
;;
;; Exercise 1.4. Observe that our model of evaluation allows for
;; combinations whose operators are compound expressions. Use this
;; observation to describe the behavior of the following procedure:
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
;; (a-plus-abs-b 2 3)
;; SICP Exercise 1.2:
;; Translate the following expression into prefix form
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 1 5)))))
(* 3 (- 6 2) (- 2 7)) )
;; => -71/300
;; or -0.236666666666667
;; SICP 1.3
;; Exercise 1.3. Define a procedure that takes three numbers as
;; arguments and returns the sum of the squares of the two larger
;; numbers.
(define (square x) (* x x))
(define (sum-of-squares a b)
(+ (square a) (square b)) )
;; Grateful thanks are given to Brian Marick (@marick) for helping me
;; write these. I got the original idea while reading through
;; http://xahlee.org/emacs/elisp_idioms.html, but couldn't work out
;; the elisp regexes. Brian Marick (@marick) stepped in and helped. He
;; took my tortured and broken camelcase-region and turned it into
;; something that actually worked. I then created
;; camelcase-word-or-region. I then wrote the snakecase versions but I
;; see now that all I did was copy the camelcase defuns over and,
;; meaning to go back and finish them Real Soon Now, forgot all about
;; them. I've had a quick look (2011-02-27) but elisp regexes are
@jimweirich
jimweirich / urinal.rb
Created February 22, 2012 01:10 — forked from st23am/urinal_etiquette.rb
Test Problem
class Urinal
def initialize(occupied, line)
@occupied = occupied
@line = line
end
def select
scores = stalls.map { |n| [score(n), n] }
best = scores.sort.last
best.first < 0 ? nil : best.last
@jimweirich
jimweirich / temp2.rb
Created September 13, 2012 20:43 — forked from jredville/temp2.rb
describe Stack do
# Suggested Syntax...
Invariants do
If { stack.empty? }
Then { stack.depth.should == 0 }
Then { stack.should be_pushable }
ElseIf { stack.full? }
Then { stack.depth.should == stack.max_depth }
Then { stack.should_not be_pushable }
describe 'EventBus methods cascade' do
Invariant { result.should == EventBus }
context 'clear' do
When(:result) { EventBus.clear }
Then { }
end
context 'publish' do
When(:result) { EventBus.publish('aa123bb', {}) }