Skip to content

Instantly share code, notes, and snippets.

@gin0606
Last active August 29, 2015 14:07
Show Gist options
  • Save gin0606/10a5e503b3884098ed27 to your computer and use it in GitHub Desktop.
Save gin0606/10a5e503b3884098ed27 to your computer and use it in GitHub Desktop.
primeFactorization :: (Integral a) => a -> [a]
primeFactorization 0 = []
primeFactorization 1 = []
primeFactorization 2 = [2]
primeFactorization x =
let fstf = firstFactor x
xx = (div x fstf)
in [fstf] ++ primeFactorization xx
firstFactor :: Integral a => a -> a
firstFactor 0 = 0
firstFactor 1 = 1
firstFactor x = firstFactor' x 2
where firstFactor' :: Integral a => a -> a -> a
firstFactor' xx n
| xx `mod` n == 0 = n
| otherwise = firstFactor' xx (n + 1)
@gin0606
Copy link
Author

gin0606 commented Oct 3, 2014

Integralの割り算はdiv使うっぽい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment