Ch4 Solution suggestion: factorize
tokdaniel opened this issue · 3 comments
tokdaniel commented
factorize :: Int -> Array Int
factorize n = do
p <- filter isPrime (1 .. (n `quot` 2))
guard $ n `mod` p == 0
[p]
tokdaniel commented
Square root of n would be even better, that would require dealing with float to int conversion, so this is easier.
to pass the tests you need
factorize :: Int -> Array Int
factorize n = do
p <- reverse $ filter isPrime (1 .. (n `quot` 2))
guard $ n `mod` p == 0
[p]
But its kind of unreasonable to test for order here.
hdgarrood commented
This looks fine to me, except I think factorize 4
should be [2, 2]
, given that the exercise asks for "the array of integers whose product is n
". It probably is worth amending the tests so that the order doesn't matter as well.