re: Daily Challenge #7 - Factorial Decomposition VIEW POST

FULL DISCUSSION
 

I can use any language right? How about MATLAB ;)

factor(factorial(n))
 

But here's a haskell solution just for fun:

import Data.List

prime_factors :: Int -> [Int]
prime_factors 1 = []
prime_factors n = next_factor : (prime_factors $ div n next_factor)
  where next_factor = head [i | i <- [2..n], 0 == mod n i]

decomp :: Int -> [Int]
decomp = sort . decomp'
  where
    decomp' 1 = []
    decomp' n = prime_factors n ++ decomp' (n - 1)
code of conduct - report abuse