Skip to content

Instantly share code, notes, and snippets.

@anwinged
Created April 1, 2019 06:42
Show Gist options
  • Save anwinged/c81521855af62259c48fb3a9070b91a5 to your computer and use it in GitHub Desktop.
Save anwinged/c81521855af62259c48fb3a9070b91a5 to your computer and use it in GitHub Desktop.
flat_prime_factors :: Integral n => n -> [n]
flat_prime_factors n =
case factors of
[] -> [n]
_ -> factors ++ flat_prime_factors (n `div` (head factors))
where
factors = take 1 $ filter fcb [2 .. int_sqrt n]
fcb x = n `mod` x == 0
int_sqrt = floor . sqrt . fromIntegral
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment