primenumbeparul 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/primenumbeparul.rb +82 -0
- metadata +46 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
module MultiplyPrimeNumbers
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def multiplyprimenumbers(numbers=nil)
|
10
|
+
no_of_primes = 150 if no_of_primes.nil?
|
11
|
+
puts "1 \n2"
|
12
|
+
|
13
|
+
i=1
|
14
|
+
nextnum=3
|
15
|
+
|
16
|
+
while i<numbers
|
17
|
+
square_root_nextnum = Math.sqrt(nextnum)
|
18
|
+
divisor = 2
|
19
|
+
while divisor <= square_root_number
|
20
|
+
break if(nextnum % divisor == 0)
|
21
|
+
divisor = divisor+1
|
22
|
+
end
|
23
|
+
|
24
|
+
if divisor > square_root_nextnum
|
25
|
+
puts nextnum
|
26
|
+
i = i+1
|
27
|
+
end
|
28
|
+
i=i+2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ActiveRecord::Base
|
35
|
+
include Math
|
36
|
+
include MultiplyPrimeNumbers
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
module Uniquify
|
49
|
+
def self.included(base)
|
50
|
+
base.extend ClassMethods
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_unique(name)
|
54
|
+
begin
|
55
|
+
self[name] = yield
|
56
|
+
end while self.class.exists?(name => self[name])
|
57
|
+
end
|
58
|
+
|
59
|
+
module ClassMethods
|
60
|
+
|
61
|
+
def uniquify(*args, &block)
|
62
|
+
options = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a }
|
63
|
+
options.merge!(args.pop) if args.last.kind_of? Hash
|
64
|
+
args.each do |name|
|
65
|
+
before_validation :on => :create do |record|
|
66
|
+
if block
|
67
|
+
record.ensure_unique(name, &block)
|
68
|
+
else
|
69
|
+
record.ensure_unique(name) do
|
70
|
+
Array.new(options[:length]) { options[:chars].to_a[rand(options[:chars].to_a.size)] }.join
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class ActiveRecord::Base
|
81
|
+
include Uniquify
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: primenumbeparul
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Parul
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Multiplying n primes
|
15
|
+
email: parulm150@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/primenumbeparul.rb
|
21
|
+
homepage: http://rubygems.org/gems/primenumbeparul
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.28
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Prime number multiplication
|
46
|
+
test_files: []
|