Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # To change this template, choose Tools | Templates
- # and open the template in the editor.
- class Integer
- def even?
- (self % 2) == 0
- end
- def odd?
- !self.even?
- end
- end
- def find_primes max
- primes = [true]
- 0.upto(max) do
- |i|
- primes[i] = true
- end
- 2.upto Math.sqrt(max) do
- |i|
- if(primes[i])
- 2.upto primes.length/i do
- |j|
- counter = j * i
- primes[counter] = false;
- end
- end
- end
- return primes
- end
- def print_nums maxindex
- primes = find_primes maxindex
- 0.upto(maxindex) do
- |i|
- if ( primes[i] )
- puts "#{i} : Prime"
- else
- puts "#{i} : Non-Prime"
- sleep 0.2
- end
- end
- end
- print_nums(200)
Add Comment
Please, Sign In to add comment