« svn replacement for git stash | Main | My New MVC Metaphor: The Command Line »

November 13, 2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54fb013da88340128759f141d970c

Listed below are links to weblogs that reference Kata:Ruby:Prime Factors:

» Kata:Ruby:Tail Recursive Prime Factors from Radyology
At the request of a former employer here's a tail recursive version of the prime factors kata in Ruby. def generate(n, factors=[]) return factors if n == 1 new_factor = (2..n).find {|f| n % f == 0} generate(n / new_factor,... [Read More]

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Fredrik Rubensson

Nice. Stuff like this makes me continue believe in programming.

unclebob

Can you make this tail recursive

Srikanth P Shreenivas

This is really amazing. After staring this code for few minutes, I realized that the trick here is the fact that any number can be expressed as factors of only prime numbers and nothing else.

The comments to this entry are closed.