[ create a new paste ] login | about

Link: http://codepad.org/xbZJhC9N    [ raw code | output | fork ]

programmingpraxis - Haskell, pasted on May 8:
import Data.List  
  
tdFactors :: Integer -> [Integer] -> [Integer]  
tdFactors n = nub . factor n . takeWhile (\x -> x * x < n)  
  where factor _ [] = []  
        factor r (x:xs) | mod r x == 0 = x : factor (div r x) (x:xs)  
                        | otherwise    = factor r xs  
  
factorNaive :: Integer -> [Integer]  
factorNaive n = tdFactors n [2..]  
  
spokes :: Integer -> [Bool]  
spokes c = map ((== 1) . gcd c) [1..c]  
  
wheel :: [Integer] -> [Integer]  
wheel ps = (ps ++) . drop 1 . map snd . filter fst $  
           zip (cycle . spokes $ product ps) [1..]  
  
factorWheel :: Integer -> [Integer]  
factorWheel n = tdFactors n $ wheel [2,3,5,7]  
  
main :: IO ()  
main = do print $ factorNaive 600851475143  
          print $ factorWheel 600851475143  


Output:
1
2
[71,839,1471,6857
Timeout


Create a new paste based on this one


Comments: