Created
April 13, 2011 06:56
-
-
Save derdewey/917094 to your computer and use it in GitHub Desktop.
Project Euler Problem 3 Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weasel> let x = Debug.Trace.trace "hi" True | |
weasel> x | |
hi | |
True | |
weasel> x | |
True | |
weasel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- factors :: (Integral a) => a -> [a] | |
-- factors x = l_factors x x [] | |
import Debug.Trace | |
isMultiple :: (Integral a) => a -> a -> Bool | |
isMultiple divisor number | |
| divisor > number = False | |
| otherwise = (number `mod` divisor) == 0 | |
factors :: (Integral a) => a -> [a] | |
factors x = l_factors x x 2 [] | |
l_factors :: (Integral a) => a-> a -> a -> [a] -> [a] | |
l_factors _ _ 1 list = list | |
l_factors orig divisee current_divisor list | |
-- | debug = undefined | |
| current_divisor > divisee = list | |
| current_divisor `isMultiple` divisee = (l_factors orig (divisee `div` current_divisor) (current_divisor+1) (current_divisor:list)) | |
| otherwise = (l_factors orig (divisee) (current_divisor+1) (list )) | |
where debug = (trace ("divisee: "++show divisee++" current_divisor: "++show current_divisor++" list: "++show list) False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment