Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Implement ADD, MULTIPLY and POWER for natural numbers
- Loading branch information
Showing
with
6 additions
and
6 deletions.
-
+3
−3
lib/nothing.rb
-
+3
−3
spec/nothing_spec.rb
|
@@ -9,9 +9,9 @@ module Nothing |
|
|
TIMES = -> n { -> f { -> x { n[f][x] } } } |
|
|
INCREMENT = -> n { -> f { -> x { f[n[f][x]] } } } |
|
|
|
|
|
# ADD = |
|
|
# MULTIPLY = |
|
|
# POWER = |
|
|
ADD = -> m { -> n { n[INCREMENT][m] } } |
|
|
MULTIPLY = -> m { -> n { n[ADD[m]][ZERO] } } |
|
|
POWER = -> m { -> n { n[MULTIPLY[m]][ONE] } } |
|
|
# DECREMENT = |
|
|
# SUBTRACT = |
|
|
|
|
|
|
@@ -11,9 +11,9 @@ |
|
|
|
|
|
specify { TIMES[representation_of 3][-> s { s + 'o' }]['hell'].should == 'hellooo' } |
|
|
specify { INCREMENT[representation_of 2].should represent 2 + 1 } |
|
|
specify { pending { ADD[representation_of 2][representation_of 3].should represent 2 + 3 } } |
|
|
specify { pending { MULTIPLY[representation_of 2][representation_of 3].should represent 2 * 3 } } |
|
|
specify { pending { POWER[representation_of 2][representation_of 3].should represent 2 ** 3 } } |
|
|
specify { ADD[representation_of 2][representation_of 3].should represent 2 + 3 } |
|
|
specify { MULTIPLY[representation_of 2][representation_of 3].should represent 2 * 3 } |
|
|
specify { POWER[representation_of 2][representation_of 3].should represent 2 ** 3 } |
|
|
specify { pending { DECREMENT[representation_of 3].should represent 3 - 1 } } |
|
|
specify { pending { SUBTRACT[representation_of 3][representation_of 2].should represent 3 - 2 } } |
|
|
|
|
|