multiprime 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +1 -0
- data/bin/multiprime +28 -0
- data/lib/multiprime.rb +14 -0
- data/multiprime.gemspec +16 -0
- data/spec/multiprime_spec.rb +25 -0
- data/spec/spec_helper.rb +27 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e081d9661235a3cefcd6d00ad8a25cb4c679ddc8
|
4
|
+
data.tar.gz: 8bd29c009c3e262f92d1ef6b1bcb2881191aa181
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2b927cce3695e6852f1a3fa17dd72da95434c20f38254052d75ca07adf41a80d7884979cdd4765520ce4782daadc1fdd3a9f5a80a0d0ecf3f70cacb295cf1d0
|
7
|
+
data.tar.gz: c90a8a180a6ab072df05eee8c4fe9f3bc6374b5f5a80383c6b90153491d9303eacc4fd1296ce3a39638e0384908e16352f8c25752d5d43c8559631059446accd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Philip Vieira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/multiprime
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
options = { count: 0 }
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
|
8
|
+
opts.banner = "Usage: multiprime [options]"
|
9
|
+
|
10
|
+
opts.on("-c", "--count [N]", Integer, "Amount of prime numbers to multiply") do |n|
|
11
|
+
options[:count] = n
|
12
|
+
end
|
13
|
+
|
14
|
+
end.parse!
|
15
|
+
|
16
|
+
require "multiprime"
|
17
|
+
|
18
|
+
matrix, range = *Multiprime.table(options[:count])
|
19
|
+
|
20
|
+
print " "
|
21
|
+
range.each {|i| print "%-3d " % i}
|
22
|
+
print "\n\n"
|
23
|
+
|
24
|
+
matrix.each_with_index do |row, index|
|
25
|
+
print "%-8d" % range[index]
|
26
|
+
row.each {|i| print "%-3d " % i}
|
27
|
+
print "\n"
|
28
|
+
end
|
data/lib/multiprime.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Multiprime
|
2
|
+
|
3
|
+
VERSION = "0.0.1"
|
4
|
+
|
5
|
+
def self.table(size)
|
6
|
+
range = primes.take(size).to_a
|
7
|
+
return range.map { |x| range.map { |y| x * y } }, range
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.primes
|
11
|
+
2.upto(Float::INFINITY).lazy.select { |n| 2.upto(Math.sqrt(n)).none? { |i| n % i == 0 } }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/multiprime.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "multiprime"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
|
7
|
+
s.name = "multiprime"
|
8
|
+
s.version = Multiprime::VERSION
|
9
|
+
s.licenses = ["MIT"]
|
10
|
+
s.authors = ["Philip Vieira"]
|
11
|
+
s.summary = "Calculates multiplication tables of prime numbers"
|
12
|
+
s.files = `git ls-files -z`.split("\x0")
|
13
|
+
s.executables = ["multiprime"]
|
14
|
+
|
15
|
+
s.add_development_dependency("rspec")
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec.describe Multiprime do
|
2
|
+
|
3
|
+
describe ".primes" do
|
4
|
+
|
5
|
+
it "returns 2, 3, 5 & 7 if 4 numbers are taken" do
|
6
|
+
expect( described_class.primes.take(4).to_a ).to eq [2,3,5,7]
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".table" do
|
12
|
+
|
13
|
+
it "returns a range of 3 prime numbers and a its multiplication matrix" do
|
14
|
+
matrix, range = *described_class.table(3)
|
15
|
+
expect( matrix ).to eq([
|
16
|
+
[4,6,10],
|
17
|
+
[6,9,15],
|
18
|
+
[10,15,25]
|
19
|
+
])
|
20
|
+
expect( range ).to eq([2,3,5])
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "multiprime"
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.filter_run :focus
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.disable_monkey_patching!
|
16
|
+
config.warnings = true
|
17
|
+
|
18
|
+
if config.files_to_run.one?
|
19
|
+
config.default_formatter = "doc"
|
20
|
+
end
|
21
|
+
|
22
|
+
config.profile_examples = 10
|
23
|
+
config.order = :random
|
24
|
+
|
25
|
+
Kernel.srand config.seed
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multiprime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philip Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables:
|
30
|
+
- multiprime
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- Rakefile
|
39
|
+
- bin/multiprime
|
40
|
+
- lib/multiprime.rb
|
41
|
+
- multiprime.gemspec
|
42
|
+
- spec/multiprime_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
homepage:
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.2.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Calculates multiplication tables of prime numbers
|
68
|
+
test_files: []
|