Okay folks, this should be simple, but maybe not.
The goal is to write a function that takes a positive integer and returns a list of its prime factors. So if you did 12 you should get the list [2, 2, 3]
As neither 1 nor zero are prime, as a result should return an empty list.
This is taken from a #tdd #Kata, so if you have not done this one I encourage you to do so. If you are not into #TDD then solve it however you like.
@Absinthe Easy to solve yes, but rather difficult to solve efficiently!
Checking for primality is not that hard either, the factorization is hard and is the reason cryptography works (certain schemes).
That said, even if it's an easier task computationally, it's not necessarily easier to implement, especially efficiently, especially for large numbers.
Sure, skip the primality test, if your genrerator does not rely on it, but who's going to test the generator?
Maybe a trivial primality test that does not need a test itself? (oh no already violating TDD) Use it to test the generator, which you can then use to test a more sophisticated primality test that you can then use to test the generator for even bigger numbers? This is a very trollish kata for TDD, and an example of a problem where you're better off relying on theory to prove correctness, an maybe only testing some components not the problem/solution as a whole.
@namark
Yea sorry I misspoke, I should have said factorization. Sieves would make it easy to chec if something is prime.
@Absinthe