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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64f892d28e0dc0337bc88e10fed11f3a80e06cb577e73c1f67daea190241dae4
4
- data.tar.gz: fc921a8f6843fad19e48f8088f85887c3abe90db2ef0525a152c096c8b74ae6e
3
+ metadata.gz: 514d544fe09239383260b8addd1c1ae183df27a5cc36e6d67a2480f80100d1a9
4
+ data.tar.gz: 4f8c796023355c3ec059bbe6742db876a05dae55ac7d7f5975c6bb2ab7cf811e
5
5
  SHA512:
6
- metadata.gz: 1115a34f67db456f69cd7316ffecbd648aa205cfd173ff4862e36b50894badf5af15fb7265410ea7c3d5dfdc102729c7a12b2f4a19cf6a3826b1cf734cfb109e
7
- data.tar.gz: bdd419507f64f4596a471a9e32d8839f42ed9a34a267316aa3c4381d4e38e04210c63ed789843b70d6861cb950e6645f320b33c2be77b9c5e4ead3273f3b0392
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/primetable`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ Primetable is a small command line utility
5
+ which prints the first N prime numbers
6
+ as a multiplication table
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+ ## Install
6
9
 
7
- ## Installation
10
+ Install as a gem with binary
8
11
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'primetable'
12
+ ```
13
+ $ gem install matthewrudy-primetable
14
+ $ primetable --help
13
15
  ```
14
16
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
17
+ Or check out the source
20
18
 
21
- $ gem install primetable
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
- TODO: Write usage instructions here
28
+ Defaults to the first 10 primes
26
29
 
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
45
+ Or we can specify N
34
46
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/primetable.
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
+ ```
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 = Array.new(n+1) { |i| Array.new(n+1) }
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
@@ -1,3 +1,3 @@
1
1
  module Primetable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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 = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Rudy Jacobs
8
8
  autorequire:
9
- bindir: exe
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
- - exe/primetable
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