generate_prime_table 0.1.1 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b1aa56b765436f89e3de28dfaa254c8a456365c
4
- data.tar.gz: 9f8f5f35eadf3c919b218d2469cf6396611ec3ec
3
+ metadata.gz: b342dbdeea1443a666cc014caa13a8cfc5219f1b
4
+ data.tar.gz: 3b41c294a05514b06a5f3515486fb8c0347ab705
5
5
  SHA512:
6
- metadata.gz: 7696bd1a27b45d70c15fcbef3a79cfee0b62ff9758ef7a16489ef841bec81f423ce27a63741572727b8865cf2ced4db7c5f6158a31fad44f28f00ca70e38146a
7
- data.tar.gz: 5a50d39bd4ee43a55124128e3bbc3dcab8b7117537616a57b0692ee7d6c4ee8467304cc60ea2f35b71eea5b525cd040a757bb3f895182ffb6303f18e7dfe926f
6
+ metadata.gz: 70c5b632c2590952ae92f3804403b08ad70f277064536f29b73b95adff99c52e0fee879f6f46a5d6109591f6603135b3fcfa3f0d316343dcfc44eedc80a3df3e
7
+ data.tar.gz: 4c034cd3342e2a31a43ae0bccdb427ddcc931e66673f160bab372cc570e3129016b2363b93e85022f74ec58463f9bdf5961d7b394ed4d25a5090fa945aa424d9
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
1
  # PrimeTable
2
2
 
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/prime_table`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ ###Objective
4
+ * Write a program that prints out a multiplication table of the first 'n' prime
5
+ numbers.(where n could be any number greater than 0)
6
+ * The program could be run from the command line and print one table to
7
+ STDOUT, or can be used as service to get the table in array to use on view.
8
+ * The first row and column of the table should have the 'n' primes, with each cell containing the product of the primes for the corresponding row and column.
6
9
 
7
10
  ## Installation
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
11
14
  ```ruby
12
- gem 'prime_table'
15
+ gem 'generate_prime_table'
13
16
  ```
14
17
 
15
18
  And then execute:
@@ -18,11 +21,77 @@ And then execute:
18
21
 
19
22
  Or install it yourself as:
20
23
 
21
- $ gem install prime_table
24
+ $ gem install generate_prime_table
22
25
 
23
26
  ## Usage
24
27
 
25
- TODO: Write usage instructions here
28
+ #####There are three ways to extract the result:
29
+ * Install the gem locally
30
+ * And
31
+ * Create a ruby file and add the following to it:
32
+ ```
33
+ require_relative 'lib/prime_table'
34
+
35
+ puts 'Enter the number'
36
+ @num = gets.chomp
37
+ @num = @num.to_i
38
+ puts PrimeTable::LESS_THAN_ZERO if @num <= 0
39
+ puts "Generating prime product table for #{@num} records" if @num > 0
40
+ table = @num <= 0 ? PrimeTable::TabularView.new : PrimeTable::TabularView.new(n:@num.to_i)
41
+ puts table.tableize
42
+
43
+ ```
44
+
45
+ * extract the result on console
46
+
47
+ ```
48
+ require 'prime_table'
49
+ @num = 10
50
+ table = PrimeTable::TabularView.new(n:@num.to_i)
51
+ puts table.tableize
52
+ ```
53
+ * try to use it as gem in application code base
54
+ ```
55
+ add "gem 'generate_prime_table'" to gemfile
56
+ bundle install
57
+ add the following in any model/module/helper file
58
+ require_relative 'lib/prime_table'
59
+ def table(num)
60
+ @table = @num <= 0 ? PrimeTable::TabularView.new : PrimeTable::TabularView.new(n:@num.to_i)
61
+ @table.tableize
62
+ end
63
+ ```
64
+
65
+ ####How to Run it using github code
66
+ clone the repo and run
67
+ ```
68
+ 'ruby table_generator_example.rb'
69
+ ```
70
+
71
+ ###Complexity Considerations:
72
+ * Generating the multiplication table is O(n**2) complexity since we have to multiply each prime by it's corresponding counterpart
73
+ * Displaying the table is O(n) since we're just iterating through the table and displaying each row. (there are 'n' number of rows)
74
+
75
+
76
+ ###Notes
77
+ • Consider complexity. How fast does your code run? How does it scale?
78
+ - As the 'N' gets bigger the program is going to start slowing down because we are using trial division to determine if the number is prime. However, for small 'n' number of primes this solution will suffice.
79
+
80
+ • Did not use the Prime class from stdlib, written custom class for it.
81
+
82
+ • Written tests to demonstrate TDD/BDD.
83
+
84
+ ###Approach
85
+
86
+ ####GetPrimes Class
87
+ * Created a GetPrimes class which will instantiate 'n' number of primes
88
+
89
+ ####Compute Primes Multiplication
90
+ * Computed the value of multiplied primes
91
+
92
+ ####Displays the Multiplication Table
93
+ * Creates a TabularView class and calls methods to display the table.
94
+
26
95
 
27
96
  ## Development
28
97
 
@@ -0,0 +1,12 @@
1
+ module PrimeTable
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../", __FILE__)
5
+ desc "copies the example rb to root directory"
6
+
7
+ def copy_initializer
8
+ template 'table_generator_example.rb', '../'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module PrimeTable
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generate_prime_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aashish Saini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-19 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,10 +71,11 @@ files:
71
71
  - Rakefile
72
72
  - bin/console
73
73
  - bin/setup
74
+ - lib/generators/prime_table/install_generator.rb
74
75
  - lib/prime_table.rb
75
76
  - lib/prime_table/version.rb
76
77
  - prime_table.gemspec
77
- - table_generator.rb
78
+ - table_generator_example.rb
78
79
  homepage: http://rubygems.org/gems/prime_table
79
80
  licenses:
80
81
  - MIT
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  requirements: []
97
98
  rubyforge_project:
98
- rubygems_version: 2.6.11
99
+ rubygems_version: 2.6.13
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: Prints the table that has N prime numberss, with each cell containing the