Skip to content

Instantly share code, notes, and snippets.

@derdewey
Created April 13, 2011 06:56
Show Gist options
  • Save derdewey/917094 to your computer and use it in GitHub Desktop.
Save derdewey/917094 to your computer and use it in GitHub Desktop.
Project Euler Problem 3 Solution
weasel> let x = Debug.Trace.trace "hi" True
weasel> x
hi
True
weasel> x
True
weasel>
-- 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