Skip to content

Instantly share code, notes, and snippets.

@nna774
Created November 6, 2012 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nna774/4024790 to your computer and use it in GitHub Desktop.
Save nna774/4024790 to your computer and use it in GitHub Desktop.
factorization
-- http://www.datapointed.net/visualizations/math/factorization/animated-diagrams/
data Factor = One | Product Int Factor deriving (Show,Eq,Read,Ord)
fact :: Int -> [Int]
fact 1 = []
fact n = p : fact (n `div` p)
where p = head $ filter ((==0).(n `mod`)) [2..]
factmap :: [Int] -> Factor
factmap [] = One
factmap (x:xs) = Product x $ factmap xs
printDots :: Factor -> IO ()
printDots f = print f -- undefined
mainLoop :: Int -> IO ()
mainLoop n = do
let f = factmap . reverse $ fact n
printDots f
mainLoop $ n + 1
main :: IO ()
main = mainLoop 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment