primal_instinct 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0d5c7b2696054f8fd380cffc3bce3e5a3a6eeba
4
+ data.tar.gz: e934c4c56d70ca6d702fda7507e0a5cf69e392bd
5
+ SHA512:
6
+ metadata.gz: bed5a6c7f8ba29277f88cc0d7e250de465c9562f2b18a30da83f6ca30dce2d0025bdb2c5fecd4427cfcea0c0ecaca442f8c3726d50d086e37e5c787e7f766d8c
7
+ data.tar.gz: f9bd6ac30aaa43d4c6424380a31b8ad4e6b35053f68f2775ba21f76b1144cabee79c7883b11ccb9b4e61a158cdc24f77c5621e04c5b8c8b055644ef14f3c9d18
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.2.1
5
+ - 2.2.2
6
+ - 2.2.3
7
+ - ruby-head
8
+ - jruby-head
9
+ before_install: gem install bundler -v 1.10.6
10
+ addons:
11
+ code_climate:
12
+ repo_token: 791e0a47aac4a5af442e2b73997420fec04c577c46bf8cba1af28351f1a57666
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in primal_instinct.gemspec
4
+ gemspec
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tomas Valent
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,69 @@
1
+ [![Build Status](https://travis-ci.org/equivalent/primal_instinct.svg)](https://travis-ci.org/equivalent/primal_instinct)
2
+ [![Code Climate](https://codeclimate.com/github/equivalent/primal_instinct/badges/gpa.svg)](https://codeclimate.com/github/equivalent/primal_instinct)
3
+ [![Test Coverage](https://codeclimate.com/github/equivalent/primal_instinct/badges/coverage.svg)](https://codeclimate.com/github/equivalent/primal_instinct/coverage)
4
+
5
+ # PrimalInstinct
6
+
7
+ This is simple gem for generating Prime Multifier Table in console
8
+
9
+ ```
10
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+
11
+ | | 2 | 3 | 5 | 7 | 11 | 13 | 17 | 19 | 23 |
12
+ | 2 | 4 | 6 | 10 | 14 | 22 | 26 | 34 | 38 | 46 |
13
+ | 3 | 6 | 9 | 15 | 21 | 33 | 39 | 51 | 57 | 69 |
14
+ | 5 | 10 | 15 | 25 | 35 | 55 | 65 | 85 | 95 | 115 |
15
+ | 7 | 14 | 21 | 35 | 49 | 77 | 91 | 119 | 133 | 161 |
16
+ | 11 | 22 | 33 | 55 | 77 | 121 | 143 | 187 | 209 | 253 |
17
+ | 13 | 26 | 39 | 65 | 91 | 143 | 169 | 221 | 247 | 299 |
18
+ | 17 | 34 | 51 | 85 | 119 | 187 | 221 | 289 | 323 | 391 |
19
+ | 19 | 38 | 57 | 95 | 133 | 209 | 247 | 323 | 361 | 437 |
20
+ | 23 | 46 | 69 | 115 | 161 | 253 | 299 | 391 | 437 | 529 |
21
+ +----+----+----+-----+-----+-----+-----+-----+-----+-----+
22
+
23
+ ```
24
+
25
+ Main focuse of the excercise was:
26
+
27
+ 1. Consider code readability/complexity
28
+ 2. Consider SOLID principles, but do not over­engineer
29
+ 3. Consider extensibility
30
+ 4. Feel free to use any library or gem in both implementation and tests, but please write your own code for the prime number generator.
31
+ 5. Consider how you can prove the correctness of your application
32
+ 6. Write it in Ruby
33
+
34
+
35
+ ## Installation
36
+
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```bash
40
+ git clone https://github.com/equivalent/primal_instinct
41
+ cd primal_instinct
42
+ bundle install
43
+ bundle exec bin/primal_instinct
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```bash
49
+ bundle exec bin/primal_instinct -h
50
+ bundle exec bin/primal_instinct --count=6
51
+ bundle exec bin/primal_instinct --count=6 -l
52
+ bundle exec bin/primal_instinct --count=6 -r
53
+ ```
54
+
55
+ ## Development
56
+
57
+ 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.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/primal_instinct. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "primal_instinct"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "primal_instinct"
5
+ require 'optparse'
6
+ require "terminal-table"
7
+
8
+ options = { generator: PrimalInstinct.generators.first }
9
+
10
+ def extract_param(gen)
11
+ gen.name.split('::').last[0].downcase
12
+ end
13
+
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: primal_instinct [options]"
16
+
17
+ PrimalInstinct.generators.each do |gen|
18
+ opts.on("-#{extract_param(gen)}", gen.name) do
19
+ options[:generator] = gen
20
+ end
21
+ end
22
+
23
+ opts.on("-cNUMBER", "--count=NUMBER", "Run verbosely") do |count|
24
+ options[:count] = count
25
+ end
26
+
27
+ opts.on("-h", "--help", "Prints this help") do
28
+ puts opts
29
+ exit
30
+ end
31
+ end.parse!
32
+
33
+
34
+ if options[:count]
35
+ args = {
36
+ generator: options.fetch(:generator),
37
+ count: options.fetch(:count).to_i
38
+ }
39
+
40
+ puts "Generating with #{options.fetch(:generator)}"
41
+
42
+ rows = PrimalInstinct.generate(args)
43
+ puts Terminal::Table.new(rows: rows)
44
+ end
@@ -0,0 +1,31 @@
1
+ module PrimalInstinct
2
+ module Generator
3
+ class LucasLehmer
4
+ attr_reader :length
5
+
6
+ def initialize(length)
7
+ @length = length
8
+ end
9
+
10
+ def call
11
+ ary = []
12
+ number = 1
13
+ until ary.length == length
14
+ number += 1
15
+ ary << number if is_prime(number)
16
+ end
17
+ ary
18
+ end
19
+
20
+ private
21
+ def is_prime(number)
22
+ return true if number == 2
23
+ return false if number.even?
24
+ (3..Math.sqrt(number)).step(2) do |i|
25
+ return false if number % i == 0
26
+ end
27
+ true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'prime'
2
+ module PrimalInstinct
3
+ module Generator
4
+ class RubyPrime
5
+ attr_reader :length
6
+
7
+ def initialize(length)
8
+ @length = length
9
+ end
10
+
11
+ def call
12
+ Prime.first(length)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module PrimalInstinct
2
+ module Multificator
3
+ def self.multification_table(values)
4
+ table = []
5
+ return table if values.empty?
6
+ ([1] + values).each do |row|
7
+ table << ([1] + values.dup).map { |e| e * row }
8
+ end
9
+ table[0][0] = nil
10
+ table
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module PrimalInstinct
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "primal_instinct/version"
2
+ require "primal_instinct/generator/lucas_lehmer"
3
+ require "primal_instinct/generator/ruby_prime"
4
+ require "primal_instinct/multificator"
5
+
6
+ module PrimalInstinct
7
+ def self.generators
8
+ PrimalInstinct::Generator
9
+ .constants
10
+ .map{ |k| self.const_get("PrimalInstinct::Generator::#{k}") }
11
+ end
12
+
13
+ def self.generate(generator:, count:)
14
+ primes = generator.new(count).call
15
+ PrimalInstinct::Multificator.multification_table(primes)
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'primal_instinct/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "primal_instinct"
8
+ spec.version = PrimalInstinct::VERSION
9
+ spec.authors = ["Tomas Valent"]
10
+ spec.email = ["equivalent@eq8.eu"]
11
+
12
+ spec.summary = %q{simple gem for generating primal table mutifications}
13
+ spec.description = %q{imple gem for generating primal table mutifications.}
14
+ spec.homepage = "https://github.com/equivalent/primal_instinct"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "terminal-table", "~> 1.5"
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.3"
34
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: primal_instinct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Valent
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: imple gem for generating primal table mutifications.
70
+ email:
71
+ - equivalent@eq8.eu
72
+ executables:
73
+ - primal_instinct
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/primal_instinct
88
+ - lib/primal_instinct.rb
89
+ - lib/primal_instinct/generator/lucas_lehmer.rb
90
+ - lib/primal_instinct/generator/ruby_prime.rb
91
+ - lib/primal_instinct/multificator.rb
92
+ - lib/primal_instinct/version.rb
93
+ - primal_instinct.gemspec
94
+ homepage: https://github.com/equivalent/primal_instinct
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ allowed_push_host: https://rubygems.org
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: simple gem for generating primal table mutifications
119
+ test_files: []