99 questions/Solutions/36

From HaskellWiki
< 99 questions‎ | Solutions
Revision as of 16:56, 13 July 2010 by Wapcaplet (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

(**) Determine the prime factors of a given positive integer.

Construct a list containing the prime factors and their multiplicity.

prime_factors_mult n = map swap $ encode $ primeFactors n
  where swap (x,y) = (y,x)

using primeFactors from problem 35 to generate the list of prime factors in ascending order, and encode from problem 10 to compress this list to a list of numbers paired with their multiplicity.