prime_number_table 2.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6137f5ad7c47eeaaf1465ea805ec5c06959a8004a0a7512ba192799ea4763707
4
+ data.tar.gz: 2069f9569547ab7201f566f3a022320648d2320b58a863be67d9b0b4336f22b3
5
+ SHA512:
6
+ metadata.gz: 10ac51a344d824895add165b556876b4b9aaffc8fbe153e814e647e2590de2832447de291c40b4c1e480344131350619704bbc9671bfadfebaea4edd7c442db2
7
+ data.tar.gz: 7554b5f022ae0486f8bdc26c884138f06ae70f052131b21e7424fb4f58f7d20e8ca297f0b852ba7d72504c49a6798637b405566347bcdfade545750dfd9481d4
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Layout/LineLength:
5
+ Max: 110
6
+
7
+ Metrics/ClassLength:
8
+ Max: 200
9
+
10
+ Metrics/AbcSize:
11
+ Max: 40
12
+
13
+ Metrics/BlockLength:
14
+ Max: 60
15
+ Exclude:
16
+ - spec/**/*
17
+
18
+ Metrics/MethodLength:
19
+ Max: 40
20
+
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 10
23
+
24
+ Metrics/PerceivedComplexity:
25
+ Max: 10
26
+
27
+ Style/ClassAndModuleChildren:
28
+ Enabled: false
29
+
30
+ Style/ClassVars:
31
+ Enabled: false
32
+
33
+ Style/Documentation:
34
+ Enabled: false
35
+
36
+ Style/MultilineBlockChain:
37
+ Enabled: false
38
+
39
+ Style/StringConcatenation:
40
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ gemspec
7
+
8
+ gem 'pry', '~> 0.13.1'
9
+ gem 'rake', '~> 12.0'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop', '~> 1.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prime_number_table (2.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ method_source (1.0.0)
13
+ parallel (1.19.2)
14
+ parser (2.7.2.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.13.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rainbow (3.0.0)
20
+ rake (12.3.3)
21
+ regexp_parser (1.8.2)
22
+ rexml (3.2.4)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.3)
28
+ rspec-support (~> 3.9.3)
29
+ rspec-expectations (3.9.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.4)
36
+ rubocop (1.0.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.7.1.5)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8)
41
+ rexml
42
+ rubocop-ast (>= 0.6.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 2.0)
45
+ rubocop-ast (1.0.1)
46
+ parser (>= 2.7.1.5)
47
+ ruby-progressbar (1.10.1)
48
+ unicode-display_width (1.7.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ prime_number_table!
55
+ pry (~> 0.13.1)
56
+ rake (~> 12.0)
57
+ rspec (~> 3.0)
58
+ rubocop (~> 1.0)
59
+
60
+ BUNDLED WITH
61
+ 2.1.4
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Evgeny Peleh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Prime number table
2
+
3
+ Displays a table of numbers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'prime_number_table'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install prime_number_table
20
+
21
+ ## Usage
22
+
23
+ $ pnt
24
+ => Please give matrix dimension (<width>x<height>)
25
+ -> 5x4
26
+ => Should I use (P)rime numbers or (F)ibonacci numbers?
27
+ -> F
28
+ => Multiplication (*) or Addition (+)
29
+ -> M
30
+
31
+ 1 1 2 3 5
32
+ 1 1 2 3 5
33
+ 2 2 4 6 10
34
+ 3 3 6 9 15
35
+
36
+ ## Development
37
+
38
+ 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.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/epeleh/prime_number_table.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'prime_number_table'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/pnt ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'prime_number_table'
5
+ PrimeNumberTable.dialog
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrimeNumberTable
4
+ VERSION = '2.2'
5
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prime_number_table/version'
4
+
5
+ module PrimeNumberTable
6
+ extend self
7
+
8
+ def dialog
9
+ width, height = loop do
10
+ printf "=> Please give matrix dimension (<width>x<height>)\n-> "
11
+ dimension = gets.delete(' ').downcase
12
+ break dimension if /^\d+x\d+$/ =~ dimension
13
+ end.split('x').map(&:to_i)
14
+
15
+ numbers = begin
16
+ printf "=> Should I use (P)rime numbers or (F)ibonacci numbers?\n-> "
17
+ input = gets.strip.downcase
18
+ { p: :prime, f: :fibonacci }.fetch(input.to_sym, input).tap(&method(:validate_numbers!))
19
+ rescue ArgumentError
20
+ retry
21
+ end
22
+
23
+ operation = begin
24
+ printf "=> Multiplication (*) or Addition (+)\n-> "
25
+ input = gets.strip.downcase
26
+ { m: :multiplication, a: :addition }.fetch(input.to_sym, input).tap(&method(:validate_operation!))
27
+ rescue ArgumentError
28
+ retry
29
+ end
30
+
31
+ puts
32
+ print(width: width, height: height, numbers: numbers, operation: operation)
33
+ puts
34
+ end
35
+
36
+ def print(table_size: nil, width: 3, height: 3, numbers: :prime, operation: :addition)
37
+ validate_numbers!(numbers)
38
+ validate_operation!(operation)
39
+
40
+ operation = { addition: :+, multiplication: :* }.fetch(operation.to_sym, operation)
41
+
42
+ (1..table_size || height).each do |row|
43
+ (1..table_size || width).each do |column|
44
+ y = public_send("#{numbers}_number", row)
45
+ x = public_send("#{numbers}_number", column)
46
+ printf('%3d ', x.public_send(operation, y))
47
+ end
48
+
49
+ puts
50
+ end
51
+
52
+ nil
53
+ end
54
+
55
+ def fibonacci_number(index)
56
+ @fibonacci_numbers ||= Hash.new { |hash, key| hash[key] = key < 2 ? key : hash[key - 1] + hash[key - 2] }
57
+ @fibonacci_numbers[index]
58
+ end
59
+
60
+ def prime_number(index)
61
+ number = 0
62
+ (index -= 1 if prime?(number += 1)) while index.positive?
63
+ number
64
+ end
65
+
66
+ def prime?(number)
67
+ return false if number < 2
68
+
69
+ @prime_numbers ||= []
70
+ @prime_numbers[number] = (2..number / 2).none? { |i| (number % i).zero? } if @prime_numbers[number].nil?
71
+ @prime_numbers[number]
72
+ end
73
+
74
+ private
75
+
76
+ def validate_numbers!(numbers)
77
+ numbers_options = %w[prime fibonacci]
78
+ return if numbers_options.include?(numbers.to_s)
79
+
80
+ raise(ArgumentError, "numbers: '#{numbers}', allowed options: '#{numbers_options.join("', '")}'")
81
+ end
82
+
83
+ def validate_operation!(operation)
84
+ operation_options = %w[addition + multiplication *]
85
+ return if operation_options.include?(operation.to_s)
86
+
87
+ raise(ArgumentError, "operation: '#{operation}', allowed options: '#{operation_options.join("', '")}'")
88
+ end
89
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/prime_number_table/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'prime_number_table'
7
+ spec.version = PrimeNumberTable::VERSION
8
+ spec.authors = ['Evgeny Peleh']
9
+ spec.email = ['pelehev@gmail.com']
10
+
11
+ spec.homepage = 'https://github.com/epeleh/prime_number_table'
12
+ spec.summary = 'CLI application'
13
+ spec.description = 'Displays a table of numbers.'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = Gem::Requirement.new('>= ' + File.read('.ruby-version').strip)
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+
22
+ spec.executables << 'pnt'
23
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prime_number_table
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.2'
5
+ platform: ruby
6
+ authors:
7
+ - Evgeny Peleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Displays a table of numbers.
14
+ email:
15
+ - pelehev@gmail.com
16
+ executables:
17
+ - pnt
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".ruby-version"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - MIT-LICENSE
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/pnt
32
+ - bin/setup
33
+ - lib/prime_number_table.rb
34
+ - lib/prime_number_table/version.rb
35
+ - prime_number_table.gemspec
36
+ homepage: https://github.com/epeleh/prime_number_table
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 3.0.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.2.3
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: CLI application
59
+ test_files: []