Skip to content

Instantly share code, notes, and snippets.

@harvimt
Created January 17, 2012 07:07
Show Gist options
  • Save harvimt/1625368 to your computer and use it in GitHub Desktop.
Save harvimt/1625368 to your computer and use it in GitHub Desktop.
Euler Problem 69
phi :: Int -> Int
phi n = length [ k | k <- [1..n], (gcd n k) == 1 ]
-- problem69_h :: Int -> Float -> Int -> Int
problem69_h cur_n max_phi max_n
| cur_n < 0 = max_n
| otherwise =
let cur_phi = (fromIntegral cur_n) / ( fromIntegral $ phi cur_n) in
if cur_phi > max_phi
then problem69_h (cur_n - 1) cur_phi cur_n
else problem69_h (cur_n - 1) max_phi max_n
problem69 = problem69_h 1000000 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment