math_probability 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ccfe5495fdef087676122ebe084faae7b63b304
4
+ data.tar.gz: e87d036731a34d8f409a184354b8018c4c112340
5
+ SHA512:
6
+ metadata.gz: c4f5fc25cbdb65a0217019830e02dabba9c73450a71e4142f76a24ecc38e1006f233fa39f172e47eb89c98e77d18b73942c72697c13ae9023a713dc5e736ffb6
7
+ data.tar.gz: 7224cce076529a33455843965028ed742e55bb41a80878c1453ed479a5736993312d98e8a81826bc5d475aa072430371b696194edab55c0738985f95fc6ecf79
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script:
7
+ - "rake"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in math_probability.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rob Race
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,31 @@
1
+ # MathProbability
2
+
3
+ [![Build Status](https://travis-ci.org/polysaturate/math_probability.png?branch=master)](https://travis-ci.org/polysaturate/math_probability)
4
+
5
+ Quickly find factorals, summnations, permutations, combanations and probability answers
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'math_probability'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install math_probability
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/math_probability'
8
+ t.test_files = FileList['test/lib/math_probability/*_test.rb']
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,43 @@
1
+ require "math_probability/version"
2
+
3
+ module MathProbability
4
+ ##
5
+ # This class encapsulates mathimatical probability methods.
6
+ class Probability
7
+
8
+ def self.sigma(start_seq, end_seq, seq_step)
9
+ summnation ||= 0
10
+ seq_step.gsub!(/((?![x-z0-9\s\.\-\+\*\/\(\)]).)*/,'').upcase!
11
+ raise ArgumentError , "Only use x,y,z as variables" if (seq_step =~ /[A-Z]/).nil?
12
+ (start_seq..end_seq).each do |value|
13
+ summnation += eval(seq_step.gsub(/[X-Z]/,value.to_s))
14
+ end
15
+ summnation
16
+ end
17
+
18
+ def self.permutations_no_repeat(objects, at_a_time)
19
+ (objects.factoral)/(objects - at_a_time).factoral
20
+ end
21
+
22
+ def self.permutations_with_repeat(objects, at_a_time)
23
+ objects**at_a_time
24
+ end
25
+
26
+ def self.combinations(objects, at_a_time)
27
+ (((objects.factoral)/((objects-at_a_time).factoral))*(1.0/(at_a_time.factoral))).to_i
28
+ end
29
+
30
+ def self.probability(choice, outcomes)
31
+ answer ||= []
32
+ a = choice.to_f / outcomes
33
+ answer << a << "#{a*100}%" << "#{choice}/#{outcomes}"
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ class Integer
40
+ def factoral
41
+ self.downto(1).inject(:*)
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module MathProbability
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'math_probability/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "math_probability"
8
+ spec.version = MathProbability::VERSION
9
+ spec.authors = ["Rob Race"]
10
+ spec.email = ["polysaturate04@aol.com"]
11
+ spec.description = %q{Quick and simple probabilty methods}
12
+ spec.summary = %q{Quickly find factorals, summnations, permutations, combanations and probability answers}
13
+ spec.homepage = "https://gitbub.com/polysaturate/math_probability"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest", "~> 4.7.3"
24
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe MathProbability::Probability do
4
+
5
+ subject { MathProbability::Probability }
6
+
7
+ it "should sigma(1, 4, '2*x + 1') equal 24" do
8
+ subject.sigma(1, 4, "2*x + 1").must_equal(24)
9
+ end
10
+
11
+ it "should not allow a bad variable in sigma()" do
12
+ proc {subject.sigma(1, 4, "2*q + 1")}.must_raise(ArgumentError)
13
+ end
14
+
15
+ it "should not allow bash in sigma()" do
16
+ proc {subject.sigma(1, 4, "ls")}.must_raise(ArgumentError)
17
+ end
18
+
19
+ it "should let permutations_no_repeat(10, 4) equal 5040" do
20
+ subject.permutations_no_repeat(10,4).must_equal(5040)
21
+ end
22
+
23
+ it "should let permutations_no_repeat(10, 4) equal 10000" do
24
+ subject.permutations_with_repeat(10,4).must_equal(10000)
25
+ end
26
+
27
+ it "should let combinations(10,4) equal 210" do
28
+ subject.combinations(10,4).must_equal(210)
29
+ end
30
+
31
+ it "should return all forms of Probability" do
32
+ subject.probability(1,2).must_equal([0.5, "50.0%", "1/2"])
33
+ end
34
+
35
+ end
36
+
37
+ describe Integer do
38
+ it "let 4! equal 24" do
39
+ 4.factoral.must_equal(24)
40
+ end
41
+
42
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe MathProbability do
4
+
5
+ it "must be defined" do
6
+ MathProbability::VERSION.wont_be_nil
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+
7
+ require File.expand_path('../../lib/math_probability.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: math_probability
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob Race
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 4.7.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.7.3
55
+ description: Quick and simple probabilty methods
56
+ email:
57
+ - polysaturate04@aol.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/math_probability.rb
69
+ - lib/math_probability/version.rb
70
+ - math_probability.gemspec
71
+ - test/lib/math_probability/math_probability_test.rb
72
+ - test/lib/math_probability/version_test.rb
73
+ - test/test_helper.rb
74
+ homepage: https://gitbub.com/polysaturate/math_probability
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Quickly find factorals, summnations, permutations, combanations and probability
98
+ answers
99
+ test_files:
100
+ - test/lib/math_probability/math_probability_test.rb
101
+ - test/lib/math_probability/version_test.rb
102
+ - test/test_helper.rb