Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created November 13, 2012 15:32
Show Gist options
  • Save PhDP/4066356 to your computer and use it in GitHub Desktop.
Save PhDP/4066356 to your computer and use it in GitHub Desktop.
primes
# Print a sequence of primes. It's not written to be fast, it's just to demonstrate
# than an infinite sequence can be compressed in a small program and thus have low
# (Kolmogorov) complexity.
def printprimes(max)
primes = []
for i in 2.. max do
primes << i if primes.inject(true) {|res, elt|
res and i % elt != 0
}
end
primes.each {|i| print i}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment