Skip to content

Instantly share code, notes, and snippets.

@qrilka
Created January 6, 2015 13:10
Show Gist options
  • Save qrilka/70fcfd28961df3151182 to your computer and use it in GitHub Desktop.
Save qrilka/70fcfd28961df3151182 to your computer and use it in GitHub Desktop.
divisors
qrilka@qdesktop ~ $ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ> let divisors1 n ds = if null subds then [n] else subd:(divisors1 (n `div` subd) (dropWhile (< subd) ds)) where subds = [i| i <- takeWhile (\x->x*x<n) ds, n `rem` i == 0];subd = head subds
λ> :set +s
λ> divisors1 93819012551 [2..]
[11,9539,894119]
(0.01 secs, 0 bytes)
λ>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment