Skip to content

Instantly share code, notes, and snippets.

@tron1point0
Created April 24, 2012 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tron1point0/2480255 to your computer and use it in GitHub Desktop.
Save tron1point0/2480255 to your computer and use it in GitHub Desktop.
npto :: (Integral a) => a -> [a]
npto x = [2,3] ++ concat [[x*6-1,x*6+1] | x <- [1..n]]
where n = ((+1) . round . sqrt . fromIntegral $ x) `div` 6
factors :: (Integral a) => a -> [a]
factors 1 = []
factors x = least : factors (x `div` least)
where least = head $ fs ++ [x]
fs = filter ((==0) . mod x) . npto $ x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment