funding_primer 0.1.1

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ results.html
2
+ pkg
3
+ html
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.3@funding_primer
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ # - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ # - jruby-18mode # JRuby in 1.8 mode
7
+ # - jruby-19mode # JRuby in 1.9 mode
8
+ # - rbx-18mode
9
+ # - rbx-19mode
10
+ # uncomment this line if your project needs to run something other than rake# script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in funding_primer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ funding_primer (0.1.1)
5
+ methadone (~> 1.2.2)
6
+ terminal-table (~> 1.4.5)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ aruba (0.5.0)
12
+ childprocess (= 0.2.3)
13
+ cucumber (>= 1.1.1)
14
+ ffi (>= 1.0.11)
15
+ rspec-expectations (>= 2.7.0)
16
+ builder (3.1.4)
17
+ childprocess (0.2.3)
18
+ ffi (~> 1.0.6)
19
+ cucumber (1.2.1)
20
+ builder (>= 2.1.2)
21
+ diff-lcs (>= 1.1.3)
22
+ gherkin (~> 2.11.0)
23
+ json (>= 1.4.6)
24
+ diff-lcs (1.1.3)
25
+ ffi (1.0.11)
26
+ gherkin (2.11.5)
27
+ json (>= 1.4.6)
28
+ json (1.7.5)
29
+ methadone (1.2.2)
30
+ bundler
31
+ rake (0.9.4)
32
+ rdoc (3.12)
33
+ json (~> 1.4)
34
+ rspec (2.12.0)
35
+ rspec-core (~> 2.12.0)
36
+ rspec-expectations (~> 2.12.0)
37
+ rspec-mocks (~> 2.12.0)
38
+ rspec-core (2.12.0)
39
+ rspec-expectations (2.12.0)
40
+ diff-lcs (~> 1.1.3)
41
+ rspec-mocks (2.12.0)
42
+ terminal-table (1.4.5)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ aruba
49
+ funding_primer!
50
+ rake (~> 0.9.2)
51
+ rdoc
52
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Gibb
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # FundingPrimer
2
+
3
+ Multiplication tables for prime numbers!
4
+
5
+ In order to visualise the products of two prime numbers, funding_primer prints out a table of prime products.
6
+
7
+ In an arguable violation of the [UNIX Philosophy](http://en.wikipedia.org/wiki/Unix_philosophy) and the [Single Responsibility Principle](http://en.wikipedia.org/wiki/Single_responsibility_principle), funding_primer also ensures that talented programmers are employed at great startups :-)
8
+
9
+ ## Build Status
10
+
11
+ [![Build Status](https://travis-ci.org/mattgibb/funding_primer.png)](https://travis-ci.org/mattgibb/funding_primer)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'funding_primer'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install funding_primer
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Help
32
+
33
+ funding_primer --help
34
+ man funding_primer
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = funding_primer - Multiplication tables for prime numbers!
2
+
3
+ Author:: Matt Gibb (matt@mattgibb.com)
4
+ Copyright:: Copyright (c) 2012 Matt Gibb
5
+
6
+
7
+ License:: MIT, see LICENSE
8
+
9
+ In order to visualise the products of two prime numbers, funding_primer prints out a table of prime products.
10
+
11
+ In an arguable violation of the {UNIX Philosophy}[http://en.wikipedia.org/wiki/Unix_philosophy] and the {Single Responsibility Principle}[http://en.wikipedia.org/wiki/Single_responsibility_principle], funding_primer also ensures that talented programmers are employed at great startups :-)
12
+
13
+ == Links
14
+
15
+ * {Source on Github}[https://github.com/mattgibb/funding_primer]
16
+ * {<img src="https://travis-ci.org/mattgibb/funding_primer.png" />}[https://travis-ci.org/mattgibb/funding_primer]
17
+ * RDoc[http://rubydoc.info/github/mattgibb/funding_primer]
18
+
19
+ == Install
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'funding_primer'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install funding_primer
32
+
33
+ == Examples
34
+
35
+ == Contributing
36
+
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
67
+ require 'fileutils'
68
+ include FileUtils::Verbose
69
+
70
+ desc "Generate man page from README.md"
71
+ task :man do
72
+ cp 'README.md', 'man/funding_primer.1.ronn'
73
+ system "ronn --organization='Matt Gibb' man/funding_primer.1.ronn"
74
+ rm 'man/funding_primer.1.ronn'
75
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'funding_primer'
6
+
7
+ class App
8
+ include FundingPrimer
9
+ include Methadone::Main
10
+ include Methadone::CLILogging
11
+
12
+ main do |number_of_primes=10|
13
+ matrix = MultiplicationTable.new(1..Integer(number_of_primes)).with_headings
14
+ formatter = Format::Table.new(matrix)
15
+ formatter.print
16
+ end
17
+
18
+ # supplemental methods here
19
+
20
+ # Declare command-line interface here
21
+
22
+ description "Multiplication tables for prime numbers!"
23
+ #
24
+ # Accept flags via:
25
+ # on("--flag VAL","Some flag")
26
+ # options[flag] will contain VAL
27
+ #
28
+ # Specify switches via:
29
+ # on("--[no-]switch","Some switch")
30
+ #
31
+ # Or, just call OptionParser methods on opts
32
+ #
33
+ # Optionally specify the number of primes
34
+ arg :number_of_primes, :optional
35
+
36
+ version FundingPrimer::VERSION
37
+
38
+ use_log_level_option
39
+
40
+ go!
41
+ end
@@ -0,0 +1,35 @@
1
+ Feature: Funding Primer outputs a table of prime numbers
2
+ In order to see that the future employee can follow instructions
3
+ As head of technical recruitment
4
+ I want to run the app with default settings
5
+
6
+ Scenario: Generate table to stdout
7
+ When I run `funding_primer`
8
+ Then the output should contain exactly:
9
+ """
10
+ +----+----+----+----+----+----+----+----+----+----+-----+
11
+ | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
12
+ +----+----+----+----+----+----+----+----+----+----+-----+
13
+ | 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
14
+ +----+----+----+----+----+----+----+----+----+----+-----+
15
+ | 2 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
16
+ +----+----+----+----+----+----+----+----+----+----+-----+
17
+ | 3 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
18
+ +----+----+----+----+----+----+----+----+----+----+-----+
19
+ | 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
20
+ +----+----+----+----+----+----+----+----+----+----+-----+
21
+ | 5 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
22
+ +----+----+----+----+----+----+----+----+----+----+-----+
23
+ | 6 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
24
+ +----+----+----+----+----+----+----+----+----+----+-----+
25
+ | 7 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
26
+ +----+----+----+----+----+----+----+----+----+----+-----+
27
+ | 8 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
28
+ +----+----+----+----+----+----+----+----+----+----+-----+
29
+ | 9 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
30
+ +----+----+----+----+----+----+----+----+----+----+-----+
31
+ | 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 |
32
+ +----+----+----+----+----+----+----+----+----+----+-----+
33
+
34
+ """
35
+ And the exit status should be 0
@@ -0,0 +1,16 @@
1
+ Feature: Funding Primer gives some basic help
2
+ In order to understand quickly what the future employee has built
3
+ As head of technical recruitment
4
+ I want to access a basic help message
5
+
6
+ Scenario: App gives a help message
7
+ When I get help for "funding_primer"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should include the version
11
+ And the banner should document that this app takes options
12
+ And the banner should document that this app's arguments are:
13
+ |number_of_primes|optional|
14
+ And there should be a one line summary of what the app does
15
+ And the following options should be documented:
16
+ |--version|
@@ -0,0 +1,21 @@
1
+ Feature: Output a user-specified number of primes
2
+ In order to fit the primes nicely on my device's screen
3
+ As a mobile user
4
+ I want to specify the size of the matrix
5
+
6
+ Scenario: Generate small table to stdout
7
+ When I run `funding_primer 3`
8
+ Then the output should contain exactly:
9
+ """
10
+ +---+---+---+---+
11
+ | | 1 | 2 | 3 |
12
+ +---+---+---+---+
13
+ | 1 | 1 | 2 | 3 |
14
+ +---+---+---+---+
15
+ | 2 | 2 | 4 | 6 |
16
+ +---+---+---+---+
17
+ | 3 | 3 | 6 | 9 |
18
+ +---+---+---+---+
19
+
20
+ """
21
+ And the exit status should be 0
File without changes
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/funding_primer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.author = "Matt Gibb"
6
+ gem.email = ["matt@mattgibb.com"]
7
+ gem.summary = %q{Multiplication tables for prime numbers!}
8
+ gem.description = %q{In order to visualise the products of two prime numbers, funding_primer will print out a table of prime products.}
9
+ gem.homepage = "http://github.com/mattgibb/funding_primer"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "funding_primer"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = FundingPrimer::VERSION
17
+ gem.add_development_dependency('rspec')
18
+ gem.add_development_dependency('rdoc')
19
+ gem.add_development_dependency('aruba')
20
+ gem.add_development_dependency('rake', '~> 0.9.2')
21
+ gem.add_dependency('methadone', '~> 1.2.2')
22
+ gem.add_dependency('terminal-table', '~> 1.4.5')
23
+ end
@@ -0,0 +1,3 @@
1
+ require "funding_primer/version"
2
+ require 'funding_primer/format'
3
+ require 'funding_primer/multiplication_table'
@@ -0,0 +1,11 @@
1
+ module FundingPrimer
2
+ # <tt>FundingPrimer::Format</tt> is a module to store classes that format the prime number output.
3
+ #
4
+ # All formatter classes employ the {Strategy Pattern}[http://en.wikipedia.org/wiki/Strategy_pattern].
5
+ # That is, they expose exactly the same interface, and only differ in their implementation. This
6
+ # allows the format of the output to be chosen dynamically, simply by choosing a formatter class.
7
+ module Format
8
+ end
9
+ end
10
+
11
+ require 'funding_primer/format/table'
@@ -0,0 +1,30 @@
1
+ require 'terminal-table'
2
+
3
+ module FundingPrimer
4
+ module Format
5
+ class Table
6
+ # store the output and initialize the table with row separators
7
+ def initialize(array,output=STDOUT)
8
+ @output = output
9
+ @table = Terminal::Table.new do |t|
10
+ # add each row apart from the last one with a separator
11
+ array[0..-2].each do |row|
12
+ t.add_row row
13
+ t.add_separator
14
+ end
15
+
16
+ # add the last row without a separator
17
+ t.add_row array.last
18
+ end
19
+
20
+ # set left and right alignments of columns
21
+ # @table.align_column
22
+ end
23
+
24
+ def print
25
+ @output.puts @table
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,38 @@
1
+ module FundingPrimer
2
+ # <tt>FundingPrimer::MultiplicationTable</tt> is a 2-dimensional multiplication table of an enumerator of numbers.
3
+ #
4
+ # It can be thought of as the Cartesian product of a vector with itself, plus some optional headings
5
+ #
6
+ class MultiplicationTable
7
+ def initialize(numbers)
8
+ @numbers = numbers.to_a
9
+ end
10
+
11
+ # produces and caches a raw 2D array of pair-wise products from @numbers
12
+ #
13
+ # Example:
14
+ #
15
+ # FundingPrimer::MultiplicationTable.new(1..3).raw_array
16
+ # # => [[1,2,3],
17
+ # # [2,4,6],
18
+ # # [3,6,9]]
19
+ def raw_array
20
+ @raw_array ||= @numbers.product(@numbers).map {|pair| pair.inject :*}.each_slice(@numbers.length).to_a
21
+ end
22
+
23
+ # produces an array with row and column headings
24
+ #
25
+ # Example:
26
+ #
27
+ # FundingPrimer::MultiplicationTable.new(1..3).with_headings
28
+ # # => [[nil,1,2,3],
29
+ # # [1, 1,2,3],
30
+ # # [2, 2,4,6],
31
+ # [3, 3,6,9]]
32
+ def with_headings
33
+ column_headings = [nil].concat @numbers
34
+ array_with_row_headings = @numbers.zip(raw_array).map &:flatten
35
+ array_with_row_headings.unshift column_headings
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,105 @@
1
+ module FundingPrimer
2
+ # FundingPrimer::Prime encapsulates the logic to generate prime numbers
3
+ class Prime
4
+ # Generates the first +n+ prime numbers. For example:
5
+ #
6
+ # FundingPrimer::Prime.first(3)
7
+ # # => [2,3,5]
8
+ def self.first(n, generator=TrialDivisionGenerator.new)
9
+ generator.first(n)
10
+ end
11
+
12
+ class BaseGenerator
13
+ # returns the first +n+ primes in an array. For example:
14
+ #
15
+ # first(3)
16
+ # # => [2,3,5]
17
+ #
18
+ # <tt>BaseGenerator#first(n)</tt> raises +NotImplementedError+.
19
+ def first(n)
20
+ raise NotImplementedError, "need to define `succ'"
21
+ end
22
+
23
+ end
24
+
25
+ # Tests for primality explicitly by brute force
26
+ #
27
+ # Modulo 2 and 3 optimisations are exploited, as well as
28
+ # testing possible prime factors only up to the square
29
+ # root of the prime candidate
30
+ class TrialDivisionGenerator < BaseGenerator
31
+ # start off @primes with 2 and 3, after which
32
+ #
33
+ # 6k ± 1, k > 0
34
+ #
35
+ # are the only candidates that are not divisible by 2 or 3
36
+ def initialize
37
+ @primes = [2,3]
38
+ @candidate = 5
39
+ @jump = 4 # jump to next candidate
40
+ # start from 5, since factors of 2 and 3 are not checked
41
+ @biggest_candidate_factor_index = 3
42
+ @next_biggest_candidate_factor_squared = 121 # 11 squared
43
+ end
44
+
45
+ # Lazily generates each successive prime that hasn't been cached yet
46
+ def first(n)
47
+ while n > @primes.length
48
+ # if necessary, add 1 extra prime to the factors that are tested
49
+ expand_candidate_factors
50
+
51
+ # append a truly prime number
52
+ append_candidate_to_primes
53
+
54
+ jump_to_next_candidate
55
+ end
56
+
57
+ @primes.take(n)
58
+ end
59
+
60
+ private
61
+ # Only prime factors up to the square root of the potential primes are checked.
62
+ # but without the performance hit of an actual square root calculation.
63
+ def expand_candidate_factors
64
+ if @candidate > @next_biggest_candidate_factor_squared
65
+ @biggest_candidate_factor_index += 1
66
+ @next_biggest_candidate_factor_squared = @primes[@biggest_candidate_factor_index + 1] ** 2
67
+ end
68
+ end
69
+
70
+ # if the candidate is prime, add it to @primes
71
+ def append_candidate_to_primes
72
+ unless @primes[2..@biggest_candidate_factor_index].find {|prime| @candidate % prime == 0 }
73
+ @primes.push @candidate
74
+ end
75
+ end
76
+
77
+ # jump is always either 2 or 4 to next candidate not divisible by 2 or 3
78
+ def jump_to_next_candidate
79
+ @candidate += @jump = 6 - @jump
80
+ end
81
+ end
82
+
83
+ class PrimorialGenerator < BaseGenerator
84
+ # Calculates the primorial of the integer +n+.
85
+ # That is, the product of the first n prime numbers.
86
+ #
87
+ # Raises an IndexError like <tt>Array#fetch</tt> if +n+ primes
88
+ # haven't been calculated and cached yet, since this function
89
+ # is intended to be used to calculate primes much bigger than +n+.
90
+ #
91
+ # NOTE: Some define primorial as the product of all of the
92
+ # prime numbers less than or equal to +n+. In this case, the
93
+ # implementation would be
94
+ #
95
+ # @primes.take_while {|p| p <= n }.inject :*
96
+ #
97
+ def primorial(n)
98
+ raise IndexError if n > @primes.length
99
+ @primes.take(n).inject(:*)
100
+ end
101
+ end
102
+
103
+ end
104
+ end
105
+
@@ -0,0 +1,3 @@
1
+ module FundingPrimer
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,85 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "FUNDING_PRIMER" "1" "November 2012" "Matt Gibb" ""
5
+ Multiplication tables for prime numbers!
6
+ .
7
+ .P
8
+ In order to visualise the products of two prime numbers, funding_primer prints out a table of prime products\.
9
+ .
10
+ .P
11
+ In an arguable violation of the UNIX Philosophy \fIhttp://en\.wikipedia\.org/wiki/Unix_philosophy\fR and the Single Responsibility Principle \fIhttp://en\.wikipedia\.org/wiki/Single_responsibility_principle\fR, funding_primer also ensures that talented programmers are employed at great startups :\-)
12
+ .
13
+ .SH "Build Status"
14
+ \fIhttps://travis\-ci\.org/mattgibb/funding_primer\fR
15
+ .
16
+ .SH "Installation"
17
+ Add this line to your application\'s Gemfile:
18
+ .
19
+ .IP "" 4
20
+ .
21
+ .nf
22
+
23
+ gem \'funding_primer\'
24
+ .
25
+ .fi
26
+ .
27
+ .IP "" 0
28
+ .
29
+ .P
30
+ And then execute:
31
+ .
32
+ .IP "" 4
33
+ .
34
+ .nf
35
+
36
+ $ bundle
37
+ .
38
+ .fi
39
+ .
40
+ .IP "" 0
41
+ .
42
+ .P
43
+ Or install it yourself as:
44
+ .
45
+ .IP "" 4
46
+ .
47
+ .nf
48
+
49
+ $ gem install funding_primer
50
+ .
51
+ .fi
52
+ .
53
+ .IP "" 0
54
+ .
55
+ .SH "Usage"
56
+ TODO: Write usage instructions here
57
+ .
58
+ .SH "Help"
59
+ .
60
+ .nf
61
+
62
+ funding_primer \-\-help
63
+ man funding_primer
64
+ .
65
+ .fi
66
+ .
67
+ .SH "Contributing"
68
+ .
69
+ .IP "1." 4
70
+ Fork it
71
+ .
72
+ .IP "2." 4
73
+ Create your feature branch (\fBgit checkout \-b my\-new\-feature\fR)
74
+ .
75
+ .IP "3." 4
76
+ Commit your changes (\fBgit commit \-am \'Added some feature\'\fR)
77
+ .
78
+ .IP "4." 4
79
+ Push to the branch (\fBgit push origin my\-new\-feature\fR)
80
+ .
81
+ .IP "5." 4
82
+ Create new Pull Request
83
+ .
84
+ .IP "" 0
85
+
@@ -0,0 +1,127 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
+ <title>funding_primer(1) - FundingPrimer</title>
7
+ <style type='text/css' media='all'>
8
+ /* style: man */
9
+ body#manpage {margin:0}
10
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
+ .mp h2 {margin:10px 0 0 0}
13
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
+ .mp h3 {margin:0 0 0 4ex}
15
+ .mp dt {margin:0;clear:left}
16
+ .mp dt.flush {float:left;width:8ex}
17
+ .mp dd {margin:0 0 0 9ex}
18
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
+ .mp pre {margin-bottom:20px}
20
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
22
+ .mp img {display:block;margin:auto}
23
+ .mp h1.man-title {display:none}
24
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
+ .mp h2 {font-size:16px;line-height:1.25}
26
+ .mp h1 {font-size:20px;line-height:2}
27
+ .mp {text-align:justify;background:#fff}
28
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
+ .mp u {text-decoration:underline}
31
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
+ .mp b.man-ref {font-weight:normal;color:#434241}
35
+ .mp pre {padding:0 4ex}
36
+ .mp pre code {font-weight:normal;color:#434241}
37
+ .mp h2+pre,h3+pre {padding-left:0}
38
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
+ ol.man-decor {width:100%}
40
+ ol.man-decor li.tl {text-align:left}
41
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
+ ol.man-decor li.tr {text-align:right;float:right}
43
+ </style>
44
+ </head>
45
+ <!--
46
+ The following styles are deprecated and will be removed at some point:
47
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
48
+
49
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
50
+ .man-navigation should be used instead.
51
+ -->
52
+ <body id='manpage'>
53
+ <div class='mp' id='man'>
54
+
55
+ <div class='man-navigation' style='display:none'>
56
+ <a href="#Build-Status">Build Status</a>
57
+ <a href="#Installation">Installation</a>
58
+ <a href="#Usage">Usage</a>
59
+ <a href="#Help">Help</a>
60
+ <a href="#Contributing">Contributing</a>
61
+ </div>
62
+
63
+ <ol class='man-decor man-head man head'>
64
+ <li class='tl'>funding_primer(1)</li>
65
+ <li class='tc'></li>
66
+ <li class='tr'>funding_primer(1)</li>
67
+ </ol>
68
+
69
+ <h1>FundingPrimer</h1>
70
+ <p>Multiplication tables for prime numbers!</p>
71
+
72
+ <p>In order to visualise the products of two prime numbers, funding_primer prints out a table of prime products.</p>
73
+
74
+ <p>In an arguable violation of the <a href="http://en.wikipedia.org/wiki/Unix_philosophy">UNIX Philosophy</a> and the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility Principle</a>, funding_primer also ensures that talented programmers are employed at great startups :-)</p>
75
+
76
+ <h2 id="Build-Status">Build Status</h2>
77
+
78
+ <p><a href="https://travis-ci.org/mattgibb/funding_primer"><img src="https://travis-ci.org/mattgibb/funding_primer.png" alt="Build Status" /></a></p>
79
+
80
+ <h2 id="Installation">Installation</h2>
81
+
82
+ <p>Add this line to your application's Gemfile:</p>
83
+
84
+ <pre><code>gem 'funding_primer'
85
+ </code></pre>
86
+
87
+ <p>And then execute:</p>
88
+
89
+ <pre><code>$ bundle
90
+ </code></pre>
91
+
92
+ <p>Or install it yourself as:</p>
93
+
94
+ <pre><code>$ gem install funding_primer
95
+ </code></pre>
96
+
97
+ <h2 id="Usage">Usage</h2>
98
+
99
+ <p>TODO: Write usage instructions here</p>
100
+
101
+ <h2 id="Help">Help</h2>
102
+
103
+ <pre><code>funding_primer --help
104
+ man funding_primer
105
+ </code></pre>
106
+
107
+ <h2 id="Contributing">Contributing</h2>
108
+
109
+ <ol>
110
+ <li>Fork it</li>
111
+ <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
112
+ <li>Commit your changes (<code>git commit -am 'Added some feature'</code>)</li>
113
+ <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
114
+ <li>Create new Pull Request</li>
115
+ </ol>
116
+
117
+
118
+
119
+ <ol class='man-decor man-foot man foot'>
120
+ <li class='tl'>Matt Gibb</li>
121
+ <li class='tc'>November 2012</li>
122
+ <li class='tr'>funding_primer(1)</li>
123
+ </ol>
124
+
125
+ </div>
126
+ </body>
127
+ </html>
@@ -0,0 +1,43 @@
1
+ # FundingPrimer
2
+
3
+ Multiplication tables for prime numbers!
4
+
5
+ In order to visualise the products of two prime numbers, funding_primer prints out a table of prime products.
6
+
7
+ In an arguable violation of the [UNIX Philosophy](http://en.wikipedia.org/wiki/Unix_philosophy) and the [Single Responsibility Principle](http://en.wikipedia.org/wiki/Single_responsibility_principle), funding_primer also ensures that talented programmers are employed at great startups :-)
8
+
9
+ ## Build Status
10
+
11
+ [![Build Status](https://travis-ci.org/mattgibb/funding_primer.png)](https://travis-ci.org/mattgibb/funding_primer)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'funding_primer'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install funding_primer
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Help
32
+
33
+ funding_primer --help
34
+ man funding_primer
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
@@ -0,0 +1,21 @@
1
+ require 'funding_primer/format/table'
2
+ require 'stringio'
3
+
4
+ include FundingPrimer::Format
5
+
6
+ describe Table do
7
+ it 'prints out a table' do
8
+ @array = [["1","2"],["3","4"]]
9
+ @io = StringIO.new
10
+ @table = Table.new @array, @io
11
+ @table.print
12
+ @io.string.should eql <<-EOS
13
+ +---+---+
14
+ | 1 | 2 |
15
+ +---+---+
16
+ | 3 | 4 |
17
+ +---+---+
18
+ EOS
19
+ end
20
+
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'funding_primer/multiplication_table'
2
+
3
+ describe FundingPrimer::MultiplicationTable do
4
+ subject { FundingPrimer::MultiplicationTable.new 1..3 }
5
+
6
+ it 'produces a raw 2D array of pair-wise products' do
7
+ subject.raw_array.should eql [[1,2,3],
8
+ [2,4,6],
9
+ [3,6,9]]
10
+ end
11
+
12
+ it 'produces an array with row and column headings' do
13
+ subject.with_headings.should eql [[nil,1,2,3],
14
+ [1, 1,2,3],
15
+ [2, 2,4,6],
16
+ [3, 3,6,9]]
17
+ end
18
+
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'mathn'
2
+ require 'funding_primer/prime'
3
+
4
+ describe FundingPrimer::Prime do
5
+ it 'generates the first 10 prime numbers' do
6
+ FundingPrimer::Prime.first(10).should eql Prime.first(10)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: funding_primer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Gibb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.2
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.2
78
+ - !ruby/object:Gem::Dependency
79
+ name: methadone
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.2.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: terminal-table
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.4.5
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.4.5
110
+ description: In order to visualise the products of two prime numbers, funding_primer
111
+ will print out a table of prime products.
112
+ email:
113
+ - matt@mattgibb.com
114
+ executables:
115
+ - funding_primer
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rvmrc
121
+ - .travis.yml
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE
125
+ - README.md
126
+ - README.rdoc
127
+ - Rakefile
128
+ - bin/funding_primer
129
+ - features/basic_table.feature
130
+ - features/help.feature
131
+ - features/set_the_size.feature
132
+ - features/step_definitions/funding_primer_steps.rb
133
+ - features/support/env.rb
134
+ - funding_primer.gemspec
135
+ - lib/funding_primer.rb
136
+ - lib/funding_primer/format.rb
137
+ - lib/funding_primer/format/table.rb
138
+ - lib/funding_primer/multiplication_table.rb
139
+ - lib/funding_primer/prime.rb
140
+ - lib/funding_primer/version.rb
141
+ - man/funding_primer.1
142
+ - man/funding_primer.1.html
143
+ - man/funding_primer.1.ronn
144
+ - spec/format/table_spec.rb
145
+ - spec/multiplication_table_spec.rb
146
+ - spec/prime_spec.rb
147
+ homepage: http://github.com/mattgibb/funding_primer
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.24
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Multiplication tables for prime numbers!
171
+ test_files:
172
+ - features/basic_table.feature
173
+ - features/help.feature
174
+ - features/set_the_size.feature
175
+ - features/step_definitions/funding_primer_steps.rb
176
+ - features/support/env.rb
177
+ - spec/format/table_spec.rb
178
+ - spec/multiplication_table_spec.rb
179
+ - spec/prime_spec.rb