matthewrudy-primetable 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +40 -21
- data/{exe → bin}/primetable +0 -0
- data/lib/primetable.rb +2 -10
- data/lib/primetable/tabulator.rb +17 -0
- data/lib/primetable/version.rb +1 -1
- data/primetable.gemspec +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 514d544fe09239383260b8addd1c1ae183df27a5cc36e6d67a2480f80100d1a9
|
4
|
+
data.tar.gz: 4f8c796023355c3ec059bbe6742db876a05dae55ac7d7f5975c6bb2ab7cf811e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c97ce959102e130f143110c408a3cd8200ba95df55e4a38e3acfaf12920d3b7ab7c15034d275377c8a8c4e6a236514375b11a767fedd45aaf3fedd165d8884d2
|
7
|
+
data.tar.gz: bdb0fd46e0279c7de3c233e6f7a9fea2f8738d745384c149c60c5ebcae098e7cf87ad1b82865fa113822e8021bf7e91713b634f3c6ab1ba69e129265652ebc3f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
primetable (0.1.0)
|
4
|
+
matthewrudy-primetable (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -27,7 +27,7 @@ PLATFORMS
|
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
29
|
bundler (~> 1.16)
|
30
|
-
primetable!
|
30
|
+
matthewrudy-primetable!
|
31
31
|
rake (~> 10.0)
|
32
32
|
rspec (~> 3.0)
|
33
33
|
|
data/README.md
CHANGED
@@ -1,35 +1,54 @@
|
|
1
1
|
# Primetable
|
2
|
+
[![Build Status](https://travis-ci.org/matthewrudy/primetable.svg?branch=master)](https://travis-ci.org/matthewrudy/primetable)
|
2
3
|
|
3
|
-
|
4
|
+
Primetable is a small command line utility
|
5
|
+
which prints the first N prime numbers
|
6
|
+
as a multiplication table
|
4
7
|
|
5
|
-
|
8
|
+
## Install
|
6
9
|
|
7
|
-
|
10
|
+
Install as a gem with binary
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem 'primetable'
|
12
|
+
```
|
13
|
+
$ gem install matthewrudy-primetable
|
14
|
+
$ primetable --help
|
13
15
|
```
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
17
|
+
Or check out the source
|
20
18
|
|
21
|
-
|
19
|
+
```
|
20
|
+
$ git clone https://github.com/matthewrudy/primetable.git
|
21
|
+
$ cd primetable
|
22
|
+
$ bundle install
|
23
|
+
$ bundle exec ruby -Ilib bin/primetable --help
|
24
|
+
```
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
Defaults to the first 10 primes
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
```
|
31
|
+
$ primetable
|
32
|
+
| 2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 | 29 |
|
33
|
+
2 | 4 | 6 | 10 | 14 | 22 | 26 | 34 | 38 | 46 | 58 |
|
34
|
+
3 | 6 | 9 | 15 | 21 | 33 | 39 | 51 | 57 | 69 | 87 |
|
35
|
+
5 | 10 | 15 | 25 | 35 | 55 | 65 | 85 | 95 | 115 | 145 |
|
36
|
+
7 | 14 | 21 | 35 | 49 | 77 | 91 | 119 | 133 | 161 | 203 |
|
37
|
+
11 | 22 | 33 | 55 | 77 | 121 | 143 | 187 | 209 | 253 | 319 |
|
38
|
+
13 | 26 | 39 | 65 | 91 | 143 | 169 | 221 | 247 | 299 | 377 |
|
39
|
+
17 | 34 | 51 | 85 | 119 | 187 | 221 | 289 | 323 | 391 | 493 |
|
40
|
+
19 | 38 | 57 | 95 | 133 | 209 | 247 | 323 | 361 | 437 | 551 |
|
41
|
+
23 | 46 | 69 | 115 | 161 | 253 | 299 | 391 | 437 | 529 | 667 |
|
42
|
+
29 | 58 | 87 | 145 | 203 | 319 | 377 | 493 | 551 | 667 | 841 |
|
43
|
+
```
|
32
44
|
|
33
|
-
|
45
|
+
Or we can specify N
|
34
46
|
|
35
|
-
|
47
|
+
```
|
48
|
+
$ primetable -n 4
|
49
|
+
| 2 | 3 | 5 | 7 |
|
50
|
+
2 | 4 | 6 | 10 | 14 |
|
51
|
+
3 | 6 | 9 | 15 | 21 |
|
52
|
+
5 | 10 | 15 | 25 | 35 |
|
53
|
+
7 | 14 | 21 | 35 | 49 |
|
54
|
+
```
|
data/{exe → bin}/primetable
RENAMED
File without changes
|
data/lib/primetable.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
require "primetable/formatter"
|
2
2
|
require "primetable/generator"
|
3
|
+
require "primetable/tabulator"
|
3
4
|
require "primetable/version"
|
4
5
|
|
5
6
|
module Primetable
|
6
7
|
def self.print(n)
|
7
8
|
primes = Primetable::Generator.new.generate(n)
|
8
|
-
table =
|
9
|
-
primes.each_with_index do |p, i|
|
10
|
-
table[0][i+1] = p
|
11
|
-
table[i+1][0] = p
|
12
|
-
|
13
|
-
primes.each_with_index do |q, j|
|
14
|
-
table[i+1][j+1] = p*q
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
9
|
+
table = Primetable::Tabulator.new.tabulate(primes)
|
18
10
|
Primetable::Formatter.new.format(table)
|
19
11
|
end
|
20
12
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Primetable
|
2
|
+
class Tabulator
|
3
|
+
def tabulate(primes)
|
4
|
+
n = primes.length
|
5
|
+
table = Array.new(n+1) { |i| Array.new(n+1) }
|
6
|
+
primes.each_with_index do |p, i|
|
7
|
+
table[0][i+1] = p
|
8
|
+
table[i+1][0] = p
|
9
|
+
|
10
|
+
primes.each_with_index do |q, j|
|
11
|
+
table[i+1][j+1] = p*q
|
12
|
+
end
|
13
|
+
end
|
14
|
+
table
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/primetable/version.rb
CHANGED
data/primetable.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
18
18
|
end
|
19
|
-
spec.bindir = "
|
20
|
-
spec.executables = spec.files.grep(%r{^
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.16"
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matthewrudy-primetable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Rudy Jacobs
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -68,10 +68,11 @@ files:
|
|
68
68
|
- Gemfile.lock
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
-
-
|
71
|
+
- bin/primetable
|
72
72
|
- lib/primetable.rb
|
73
73
|
- lib/primetable/formatter.rb
|
74
74
|
- lib/primetable/generator.rb
|
75
|
+
- lib/primetable/tabulator.rb
|
75
76
|
- lib/primetable/version.rb
|
76
77
|
- primetable.gemspec
|
77
78
|
homepage: https://github.com/matthewrudy/primetable
|