Created
January 30, 2011 20:24
-
-
Save ogijun/803210 to your computer and use it in GitHub Desktop.
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
-- Ramanujan Numbers: | |
-- c.f. http://www.ipl.t.u-tokyo.ac.jp/~onoue/pub/jssst01.pdf | |
module Main where | |
main = print (take 10 (ramanujan (\(a,b) -> a^3 + b^3))) | |
ramanujan f = [(x,y) | (x,y)<- zip s (tail s), f x == f y] where s = fsort f 1 | |
fsort f k = (k,k) : fmerge f [(k,b) | b<-[k+1..]] (fsort f (k+1)) | |
fmerge f (x:xs) (y:ys) | |
| f x <= f y = x : fmerge f xs (y:ys) | |
| otherwise = y : fmerge f (x:xs) ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment