Skip to content

Instantly share code, notes, and snippets.

@hyphenrf
Created February 4, 2022 00:34
Show Gist options
  • Save hyphenrf/b4ead1827671bc39a947c2153e879bc3 to your computer and use it in GitHub Desktop.
Save hyphenrf/b4ead1827671bc39a947c2153e879bc3 to your computer and use it in GitHub Desktop.
cute and reasonably fast lazy ramanujan numbers
zipper xs = ([], xs)
next (xs, y:ys) = (y:xs, ys)
next z = z
rmj n = take n naive
where
naive = go $ zipper [ x^3 + y^3 | x <- [1..], y <- [1..x] ]
go (_,[]) = []
go xs@(l,n:_) = let ns = go $ next xs in
if elem n l then n : ns else ns
main = print $ rmj 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment