Skip to content

Instantly share code, notes, and snippets.

@dukeimg
Created February 28, 2016 11:07
Show Gist options
  • Save dukeimg/9b39e4187fc87b6f8bc8 to your computer and use it in GitHub Desktop.
Save dukeimg/9b39e4187fc87b6f8bc8 to your computer and use it in GitHub Desktop.
Simple number finder
def find(n)
unless n < 2 || n % 2 == 0 && n != 2
arr = []
n.times do |a|
arr.push(a) if a < (Math.sqrt(n) + 1).floor && a > 1
end
check = lambda {|num| n % num == 0}
if arr.select(&check).empty?
puts "SN ##{$c + 1}: #{n}"
$c += 1
end
end
end
$c = 0
c = 0
puts 'How many simple numbers do you need?'
count = gets.chomp.to_i
until $c == count
find(c)
c += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment