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