ruborithms 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +46 -0
- data/lib/ruborithms.rb +1 -0
- data/lib/ruborithms/algorithms/binary_search.rb +4 -6
- data/lib/ruborithms/algorithms/linear_search.rb +4 -4
- data/lib/ruborithms/algorithms/selection_sort.rb +43 -0
- data/lib/ruborithms/version.rb +2 -2
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb1af959d7f9e5582758c9ab7a2aa43b09c7fac
|
4
|
+
data.tar.gz: 39c1f371e6de97f071f062306de2161f6eccb3bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7554268867411a4aaea59515042ccb9c0e4a1f24bf4b3f7574c8a129dc4688225b2a91c9643f918e817d0a4c817d5ee0185714690f0d972100f898ea57eef8e0
|
7
|
+
data.tar.gz: 767bf0aba13f50c341ab2cf4bdad01a6567d6c6e4350a5cf61b308082bf126dd8cf9d3d183af76ccf2a6b7268b6732134dbafc79f42aba7744fb73099fd58626
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruborithms (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
parser (2.4.0.0)
|
12
|
+
ast (~> 2.2)
|
13
|
+
powerpack (0.1.1)
|
14
|
+
rainbow (2.2.1)
|
15
|
+
rspec (3.5.0)
|
16
|
+
rspec-core (~> 3.5.0)
|
17
|
+
rspec-expectations (~> 3.5.0)
|
18
|
+
rspec-mocks (~> 3.5.0)
|
19
|
+
rspec-core (3.5.4)
|
20
|
+
rspec-support (~> 3.5.0)
|
21
|
+
rspec-expectations (3.5.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.5.0)
|
24
|
+
rspec-mocks (3.5.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.5.0)
|
27
|
+
rspec-support (3.5.0)
|
28
|
+
rubocop (0.48.1)
|
29
|
+
parser (>= 2.3.3.1, < 3.0)
|
30
|
+
powerpack (~> 0.1)
|
31
|
+
rainbow (>= 1.99.1, < 3.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
34
|
+
ruby-progressbar (1.8.1)
|
35
|
+
unicode-display_width (1.2.1)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
rspec (~> 3.5)
|
42
|
+
rubocop (~> 0.48.1)
|
43
|
+
ruborithms!
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
1.14.6
|
data/lib/ruborithms.rb
CHANGED
@@ -11,17 +11,15 @@ module Ruborithms
|
|
11
11
|
def binary_search(object, value)
|
12
12
|
min = 0
|
13
13
|
max = object.count - 1
|
14
|
-
while
|
14
|
+
while max >= min
|
15
15
|
avg = ((max + min) / 2).floor
|
16
|
-
if object[avg] == value
|
17
|
-
|
18
|
-
|
19
|
-
max = avg - 1
|
16
|
+
return avg if object[avg] == value
|
17
|
+
if object[avg] > value
|
18
|
+
max = avg - 1
|
20
19
|
else
|
21
20
|
min = avg + 1
|
22
21
|
end
|
23
22
|
end
|
24
|
-
nil
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Ruborithms
|
1
|
+
module Ruborithms
|
2
2
|
module Algorithms
|
3
3
|
module LinearSearch
|
4
4
|
class << self
|
@@ -9,9 +9,9 @@ module Ruborithms
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
def linear_search(object, value)
|
12
|
-
object.
|
13
|
-
return
|
14
|
-
end
|
12
|
+
0.upto(object.count - 1) do |i|
|
13
|
+
return i if value == object[i]
|
14
|
+
end; nil
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ruborithms
|
2
|
+
module Algorithms
|
3
|
+
module SelectionSort
|
4
|
+
class << self
|
5
|
+
def included(mod)
|
6
|
+
mod.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def selection_sort(object)
|
12
|
+
0.upto(object.count - 1) do |i|
|
13
|
+
min_value_index = find_index_of_min_value(object, i)
|
14
|
+
swap(object, i, min_value_index)
|
15
|
+
end
|
16
|
+
object
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def find_index_of_min_value(object, i)
|
22
|
+
min_index = i
|
23
|
+
min_value = object[i]
|
24
|
+
i.upto(object.count - 1) do |j|
|
25
|
+
if object[j] < min_value
|
26
|
+
min_index = j
|
27
|
+
min_value = object[j]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
min_index
|
31
|
+
end
|
32
|
+
|
33
|
+
def swap(object, i, min_index)
|
34
|
+
object[i], object[min_index] = object[min_index], object[i]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def selection_sort
|
39
|
+
self.class.selection_sort(self)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/ruborithms/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Ruborithms
|
2
|
-
VERSION = '0.
|
1
|
+
module Ruborithms
|
2
|
+
VERSION = '0.3.0'.freeze
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruborithms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zinovyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,16 +24,35 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.5'
|
27
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.48.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.48.1
|
41
|
+
description: Algorithms and data structures implemented in Ruby
|
28
42
|
email: vanyazin@gmail.com
|
29
43
|
executables: []
|
30
44
|
extensions: []
|
31
45
|
extra_rdoc_files: []
|
32
46
|
files:
|
33
47
|
- ".gitignore"
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
34
52
|
- lib/ruborithms.rb
|
35
53
|
- lib/ruborithms/algorithms/binary_search.rb
|
36
54
|
- lib/ruborithms/algorithms/linear_search.rb
|
55
|
+
- lib/ruborithms/algorithms/selection_sort.rb
|
37
56
|
- lib/ruborithms/version.rb
|
38
57
|
homepage: https://github.com/zinovyev/ruborithms
|
39
58
|
licenses:
|
@@ -58,5 +77,5 @@ rubyforge_project:
|
|
58
77
|
rubygems_version: 2.6.8
|
59
78
|
signing_key:
|
60
79
|
specification_version: 4
|
61
|
-
summary: Algorithms and data structures
|
80
|
+
summary: Algorithms and data structures implemented in Ruby
|
62
81
|
test_files: []
|