Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement TO_DIGITS for natural numbers
def to_digits(n)
  (n <= 9 ? [] : to_digits(n / 10)).push(n % 10)
end
  • Loading branch information
tomstuart committed Oct 28, 2011
1 parent b31dde6 commit 97ed146
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/nothing.rb
Expand Up @@ -72,7 +72,9 @@ module Nothing

# Natural numbers with lists

# TO_DIGITS =
TEN = INCREMENT[MULTIPLY[THREE][THREE]]
RADIX = TEN
TO_DIGITS = Z[-> f { -> n { PUSH[IF[IS_LESS_OR_EQUAL[n][DECREMENT[RADIX]]][EMPTY][ -> _ { f[DIV[n][RADIX]][_] } ]][MOD[n][RADIX]] } }]
# TO_STRING =

# FizzBuzz
Expand Down
2 changes: 1 addition & 1 deletion spec/nothing_spec.rb
Expand Up @@ -37,7 +37,7 @@
end

context 'with lists' do
specify { pending { TO_DIGITS[representation_of 42].should represent [4, 2] } }
specify { TO_DIGITS[representation_of 42].should represent [4, 2] }
end

context 'with strings' do
Expand Down

0 comments on commit 97ed146

Please sign in to comment.