Skip to content

Instantly share code, notes, and snippets.

@emadshaaban92
Created February 1, 2014 00:44
Show Gist options
  • Save emadshaaban92/8746300 to your computer and use it in GitHub Desktop.
Save emadshaaban92/8746300 to your computer and use it in GitHub Desktop.
INDEX = 10001
iter numbers = Iter.init(2, function(int elm){ elm + 1 }, function(int elm){ elm > 0 })
function iter remove_multiples(int a, iter seq){
Iter.filter(function(int elm){ mod(elm, a) != 0 }, seq)
}
function primes_init(iter seq){
match(seq.next()){
case {none} : { next : function () { none } }
case {some:it} : { next : function () { some((it.f1, primes_init(remove_multiples(it.f1, it.f2)))) } }
}
}
iter primes = primes_init(numbers)
option number = Iter.skip(INDEX - 1, primes).next()
jlog(Int.to_string(Option.get(number).f1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment