Created
          February 28, 2016 11:07 
        
      - 
      
- 
        Save dukeimg/9b39e4187fc87b6f8bc8 to your computer and use it in GitHub Desktop. 
    Simple number finder
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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