Skip to content

Instantly share code, notes, and snippets.

@ogijun
Created January 30, 2011 20:24
Show Gist options
  • Save ogijun/803210 to your computer and use it in GitHub Desktop.
Save ogijun/803210 to your computer and use it in GitHub Desktop.
-- 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