tg_fibonacci 1.0.0

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: e6ad83f0d83603fbd1c6dd3e3db57a4ebd0f0e949c64a47f95e92003acc930ff
4
+ data.tar.gz: f95337b55e16e78569e0a28bc7295c49e8eabff2932166b3b1d54a6f7366bbfc
5
+ SHA512:
6
+ metadata.gz: e16d3bf930d118d1205c03ab059b537bd556805951245fcb61abc4c07fb505cd57f0e1984ee02452271c96e6c2cd692a409c25311449fc378ef1c0bb1805f131
7
+ data.tar.gz: 91223d3854b5de1476b7cc547103d38559f343c8901cac6fec6185fb889299b788840749104ebbcced0bf8143b415ab59726ab2f4e5c4e1bfea98cd2a3d24809
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2020 Ian Johnson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ # TG Fibonacci
data/bin/tg_fib ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/fibonacci/fibonacci'
4
+
5
+ number = ARGV.shift
6
+
7
+ if number
8
+ puts Fibonacci::Fibonacci.seq_string(number.to_i)
9
+ else
10
+ loop do
11
+ puts "\nPlease enter your n to get fib(n) ('quit' to exit)"
12
+ command = gets.chomp.downcase
13
+ case command
14
+ when /^\d+$/
15
+ puts Fibonacci::Fibonacci.seq_string(command.to_i)
16
+ when 'quit', 'exit'
17
+ break
18
+ else
19
+ puts "Please enter a number or 'quit'"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Fibonacci
2
+ class Fibonacci
3
+ def self.seq_string(number)
4
+ "fib(#{number}) = #{self.sequence(number).join(', ')}"
5
+ end
6
+
7
+ def self.sequence(number)
8
+ (0..number).to_a.map { |n| self.fibonacci(n) }
9
+ end
10
+
11
+ def self.fibonacci(number)
12
+ return 1 if number == 0 || number == 1
13
+ self.fibonacci(number - 1) + self.fibonacci(number - 2)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,55 @@
1
+ require 'fibonacci/fibonacci'
2
+
3
+ module Fibonacci
4
+ describe Fibonacci do
5
+ it 'generates the correct number for fib(0)' do
6
+ result = Fibonacci.fibonacci(0)
7
+ expect(result).to eq(1)
8
+ end
9
+
10
+ it 'generates the correct number for fib(1)' do
11
+ result = Fibonacci.fibonacci(1)
12
+ expect(result).to eq(1)
13
+ end
14
+
15
+ it 'generates the correct number for fib(2)' do
16
+ result = Fibonacci.fibonacci(2)
17
+ expect(result).to eq(2)
18
+ end
19
+
20
+ it 'generates the correct number for fib(3)' do
21
+ result = Fibonacci.fibonacci(3)
22
+ expect(result).to eq(3)
23
+ end
24
+
25
+ it 'generates the correct number for fib(4)' do
26
+ result = Fibonacci.fibonacci(4)
27
+ expect(result).to eq(5)
28
+ end
29
+
30
+ it 'generates the proper sequence for fib(0)' do
31
+ result = Fibonacci.sequence(0)
32
+ expect(result).to eq([1])
33
+ end
34
+
35
+ it 'generates the proper sequence for fib(1)' do
36
+ result = Fibonacci.sequence(1)
37
+ expect(result).to eq([1, 1])
38
+ end
39
+
40
+ it 'generates the proper sequence for fib(2)' do
41
+ result = Fibonacci.sequence(2)
42
+ expect(result).to eq([1, 1, 2])
43
+ end
44
+
45
+ it 'generates the proper sequence for fib(3)' do
46
+ result = Fibonacci.sequence(3)
47
+ expect(result).to eq([1, 1, 2, 3])
48
+ end
49
+
50
+ it 'generates the proper sequence for fib(4)' do
51
+ result = Fibonacci.sequence(4)
52
+ expect(result).to eq([1, 1, 2, 3, 5])
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tg_fibonacci
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: "# TG Fibonacci"
28
+ email: tacoda@pm.me
29
+ executables:
30
+ - tg_fib
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README
36
+ - bin/tg_fib
37
+ - lib/fibonacci/fibonacci.rb
38
+ - spec/fibonacci/fibonacci_spec.rb
39
+ homepage: https://github.com/tacoda/tg_fibanacci
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '1.9'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.0.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Generate the fibonacci sequence
62
+ test_files:
63
+ - spec/fibonacci/fibonacci_spec.rb