Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created August 2, 2010 00:25
Show Gist options
  • Select an option

  • Save jsoffer/503939 to your computer and use it in GitHub Desktop.

Select an option

Save jsoffer/503939 to your computer and use it in GitHub Desktop.
import Data.Numbers.Primes(primes)
import Data.List(sort, sortBy)
rad :: Integer -> Integer
rad n = product $ f n primes where
f :: Integer -> [Integer] -> [Integer]
f 1 _ = []
f x (y:ys) = if mod x y == 0
then y : f (remove y x) ys
else f x ys
remove factor num = if mod num factor == 0
then remove factor (quot num factor)
else num
lista = map (\k -> (k,rad k)) [1..100000]
ordena :: (Ord a, Ord b) => [(a,b)] -> [(a,b)]
ordena = sortBy (\ a b -> compare (snd a) (snd b))
main = putStrLn $ show $ (ordena $ sort lista) !! 9999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment