Guest User

Untitled

a guest
Dec 13th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Compose an array, then 'tap' it to begin iterating over its values;
  2. # our bounds are 2 .. X-2, where X is last digit we want to test.
  3. # The last operation performed, the select, accepts only non-nil
  4. # values.
  5. Array.new( (ARGV[0] || 1000).to_i - 2 ){|i| i + 2 }.tap {|it|
  6. it.each_with_index {|v, i|
  7. next unless v
  8.  
  9. # We actually only test slices of it, since we already know that
  10. # any given number is divisible by itself.
  11. it[ i + 1 .. it.length - 1 ].each {|n|
  12. next unless n
  13.  
  14. # If it's a factor, remove it!
  15. it.delete( n ) if n % v == 0
  16. }
  17. }
  18. }.select {|r| !!r }
Add Comment
Please, Sign In to add comment