Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env ruby
require 'inline'
class Primes
inline do |builder|
builder.c '
void prime(unsigned long amount) {
int *list;
unsigned long i,x,d;
list = malloc(sizeof(int)*(amount));
for (i=2; i <= amount; i++){
list[i] = 1;
}
for(x=2; x<=amount; x++) {
if (list[x]) {
for (d = x; d * x < amount ; d++) {
list[d * x] = 0;
}
}
}
for (i=2; i < amount; i++){
if (list[i]){
printf("%d\n",i);
}
}
}'
end
end
def help
puts "#{$0} <primes_up_to>"
end
begin
unless ARGV.length == 1
help
exit(1)
end
prime = Primes.new
prime.prime(ARGV[0].to_i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.