hd1

sieve of eratosthenes

hd1
Dec 5th, 2014
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.40 KB | None | 0 0
  1. require 'prime'
  2. primes = Array.new
  3. counter = ARGV[0].to_i
  4. counter = 30 if counter == 0
  5. (2..counter).to_a.each { |x|
  6.   if Prime.prime? x then
  7.     primes << x
  8.   end
  9. }
  10.  
  11. x = primes
  12. y = primes
  13.  
  14. print '     '
  15. x.each {|i| print "%-3d  " % i}
  16. print "\n     "
  17. x.each {|i| print '---- '}
  18. print "\n"
  19.  
  20. y.each do |j|
  21.    print "%-3d| " % j
  22.    x.each {|i| print "%-3d  " % (i*j)}
  23.    print "\n"
  24. end
Advertisement
Add Comment
Please, Sign In to add comment