Skip to content

Instantly share code, notes, and snippets.

@radar
Created August 12, 2010 09:54
Show Gist options
  • Select an option

  • Save radar/520658 to your computer and use it in GitHub Desktop.

Select an option

Save radar/520658 to your computer and use it in GitHub Desktop.
class Numeric
def prime?
basics = (2..10).to_a
return false if basics.detect { |n| self % n == 0 }
factors == [1, self]
end
def factors
@factors ||= (1..self).to_a.select { |n| self % n == 0 }
end
end
@sandstrom

Copy link
Copy Markdown

Nice solution! Just out of curiosity, was my attempt just way off or was the approach doable but with some minor error/bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment