Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created April 4, 2011 09:39
Show Gist options
  • Save pokutuna/901369 to your computer and use it in GitHub Desktop.
Save pokutuna/901369 to your computer and use it in GitHub Desktop.
n = gets.to_i
prims = []
list = (2..n).to_a
while true
head = list.shift
prims.push head
list.delete_if{ |i| i % head == 0 }
break if prims.max ** 2 > list.max
end
puts prims + list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment