Definition:
A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself
Basically the purpose of this post is to write the programs for mathematical algorithms.Prime number was most used in math challenges and in technical discussions.
I have just started working on Unit test, algorithms and patterns, so i decided to write test cases for the most of my ruby programs.
Is Prime or Not?:
class Prim def is_prime(n) return false if n<2 2.upto(Math.sqrt(n).to_i){|i| return false if n%i==0} return true end end
No comments :
Post a Comment