six45 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in six45.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'debugger'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Felix Wang
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,32 @@
1
+ # Six45
2
+
3
+ A Gem helps pick 6 numbers out of 45.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'six45'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install six45
18
+
19
+ ## Usage
20
+
21
+ Run 'six45' in commandline:
22
+
23
+ # six45 => Returns 10 games
24
+ # six45 30 => Returns 30 games
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/six45 ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'six45'
4
+ require 'pp'
5
+
6
+ number_of_games = Six45.is_number?(ARGV[0]) ? ARGV[0].to_i : 10
7
+ Six45.pick(number_of_games).each { |key, game| pp game }
@@ -0,0 +1,13 @@
1
+ module Six45
2
+ class Seeds
3
+ def initialize(min=1, max=13)
4
+ @min = min
5
+ @max = max
6
+ end
7
+
8
+ def generate
9
+ 6.times.map{rand(@min..@max)}
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Six45
2
+ VERSION = "0.0.1"
3
+ end
data/lib/six45.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "six45/version"
2
+ require "six45/seeds"
3
+
4
+ module Six45
5
+ extend self
6
+
7
+ def seed
8
+ Seeds.new.generate
9
+ end
10
+
11
+ def lucky_candidates
12
+ lucky_seed = seed
13
+ candidates = []
14
+ while lucky_seed.size > 0
15
+ candidates << lucky_seed.inject { |sum, d| sum+d }
16
+ lucky_seed.pop
17
+ end
18
+ candidates.sort
19
+ end
20
+
21
+ def luck_numbers
22
+ numbers = lucky_candidates
23
+ if numbers.inject { |sum, d| d > 45 } || numbers.inject{ |sum, d| sum+d } < 60
24
+ luck_numbers
25
+ else
26
+ numbers
27
+ end
28
+ end
29
+
30
+ def pick number_of_games=10
31
+ games = {}
32
+ number_of_games.times do |i|
33
+ games[i] = luck_numbers
34
+ end
35
+ games
36
+ end
37
+
38
+ def is_number?(i)
39
+ true if Float(i) rescue false
40
+ end
41
+
42
+ end
data/six45.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/six45/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Felix Wang"]
6
+ gem.email = ["moom.felix@gmail.com"]
7
+ gem.description = %q{A Gem helps pick 6 digits out of 45.}
8
+ gem.summary = %q{A Gem helps pick 6 digits out of 45.}
9
+ gem.homepage = "https://github.com/moom/six45.git"
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 = "six45"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Six45::VERSION
17
+ end
@@ -0,0 +1,50 @@
1
+ require "six45"
2
+
3
+ describe Six45 do
4
+
5
+ context "#seed" do
6
+ let(:seed) { Six45.seed }
7
+ it "returns an array" do
8
+ seed.should be_kind_of(Array)
9
+ end
10
+ it "containing 6 numbers" do
11
+ seed.size.should eq(6)
12
+ end
13
+ it "each number is less than 13" do
14
+ seed.each { |n| n.should be <= 13 }
15
+ end
16
+ end
17
+
18
+ context "#pick" do
19
+ let(:seed) { Six45.seed }
20
+ let(:lucky_numbers) { Six45.pick }
21
+ let(:pick_five) { lambda { Six45.pick 5 } }
22
+ it "returns an hash" do
23
+ lucky_numbers.should be_kind_of(Hash)
24
+ end
25
+ it "containing 10 games" do
26
+ lucky_numbers.size.should be 10
27
+ end
28
+ it "each game contains 6 numbers" do
29
+ lucky_numbers.each { |k, g| g.size.should eq(6) }
30
+ end
31
+ it "each number is unique" do
32
+ lucky_numbers.each { |k, g| g.uniq.size.should eq g.size }
33
+ end
34
+ it "each number is less than 45" do
35
+ lucky_numbers.each { |k, g| g.each { |n| n.should be <= 45 } }
36
+ end
37
+ it "sum of all numbers is greater than 60" do
38
+ lucky_numbers.each { |k, g| g.inject { |sum, n| sum+n }.should be > 60 }
39
+ end
40
+ it "also accepts an integer argument 5" do
41
+ pick_five.call.should_not raise_error ArgumentError
42
+ end
43
+ it "returns an hash" do
44
+ pick_five.call.should be_kind_of(Hash)
45
+ end
46
+ it "containing 5 games" do
47
+ pick_five.call.size.should be 5
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: six45
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Felix Wang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Gem helps pick 6 digits out of 45.
15
+ email:
16
+ - moom.felix@gmail.com
17
+ executables:
18
+ - six45
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/six45
28
+ - lib/six45.rb
29
+ - lib/six45/Seeds.rb
30
+ - lib/six45/version.rb
31
+ - six45.gemspec
32
+ - spec/six45_spec.rb
33
+ homepage: https://github.com/moom/six45.git
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.21
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A Gem helps pick 6 digits out of 45.
57
+ test_files:
58
+ - spec/six45_spec.rb