Created
November 13, 2012 15:32
-
-
Save PhDP/4066356 to your computer and use it in GitHub Desktop.
primes
This file contains hidden or 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
# 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