victory 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/USAGE.md +73 -25
- data/lib/containers/tuple.rb +3 -2
- data/lib/victory/version.rb +1 -1
- data/lib/victory.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00bcbcbc7b4fc5a87806420fd5be8e30e7719ce1212b6b674e08d9ace7e72fdd
|
4
|
+
data.tar.gz: 31ee4514bcb2997b72aee5ea38eec75630ad0181c870ee79d3d16dab0e41d709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c141a43232ac8012bf7add4eb505c19f6e4dd378b7fb808319646cf1e45d6156bf2f3b47529cf73aa7cbdb8eb464264783b015b95a1f01c33efe1e3bd09c352
|
7
|
+
data.tar.gz: 29c366ee9083993a489f6263a630ac16e8e3dd4d0c653bebce97ce996adfeda2faed40deacbd7b495f89387a791bf8a8881ff73afc2c5762815e5270e52f88be
|
data/USAGE.md
CHANGED
@@ -4,15 +4,50 @@ In this markdown you will see the usage of all the datastructures and algorithms
|
|
4
4
|
|
5
5
|
# Data Structures
|
6
6
|
|
7
|
+
* [Ranges and Loops](#ranges)
|
8
|
+
* [Complex](#complex)
|
7
9
|
* [Array](#array)
|
8
10
|
* [Hash](#hash)
|
9
|
-
* [Set](#set)
|
10
11
|
* [Struct](#struct)
|
12
|
+
* [Matrix](#matrix)
|
13
|
+
* [Set](#set)
|
11
14
|
* [OpenStruct](#openstruct)
|
12
15
|
* [Tuple](#tuple)
|
13
16
|
* [Graph](#graph)
|
14
17
|
* [IOHelpers](#io-helpers)
|
15
18
|
|
19
|
+
<a name="ranges" />
|
20
|
+
|
21
|
+
## Ranges and loops
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
5.times { |x| puts x } # displays numbers from 0 to 5
|
25
|
+
3.upto(7) { |x| puts x } # displays numbers from 3 to 7
|
26
|
+
5.downto(3) { |x| puts x } # displays numbers from 5 to 3
|
27
|
+
0.step(10, 2) { |x| puts x } # displays 0, 2, 4, 6, 8, 10
|
28
|
+
12.step(6, -2) { |x| puts x } # displays 12, 10, 8, 6
|
29
|
+
(0...1).step(0.1) { |x| puts x } # displays 0.0, 0.1, ... , 0.8, 0.9
|
30
|
+
loop { |x| puts x } # infinite loop
|
31
|
+
```
|
32
|
+
|
33
|
+
<a name="complex" />
|
34
|
+
|
35
|
+
## Complex
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
a = 1+2i
|
39
|
+
# => (1+2i)
|
40
|
+
a.real
|
41
|
+
# => 1
|
42
|
+
a.imag
|
43
|
+
# => 2
|
44
|
+
a.rect
|
45
|
+
# => [1, 2]
|
46
|
+
r, i = a.rect
|
47
|
+
r + i.i
|
48
|
+
# => (1+2i)
|
49
|
+
```
|
50
|
+
|
16
51
|
<a name="array" />
|
17
52
|
|
18
53
|
## Array
|
@@ -58,23 +93,6 @@ a[1]
|
|
58
93
|
# => 2
|
59
94
|
```
|
60
95
|
|
61
|
-
<a name="set" />
|
62
|
-
|
63
|
-
## Set
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
require 'set'
|
67
|
-
|
68
|
-
s = Set.new
|
69
|
-
# => #<Set: {}>
|
70
|
-
s << :a
|
71
|
-
# => #<Set: {:a}>
|
72
|
-
s << :a
|
73
|
-
# => #<Set: {:a}>
|
74
|
-
s << :b
|
75
|
-
# => #<Set: {:a, :b}>
|
76
|
-
```
|
77
|
-
|
78
96
|
<a name="struct" />
|
79
97
|
|
80
98
|
## Struct
|
@@ -92,7 +110,7 @@ my_face.hair
|
|
92
110
|
my_face.nose
|
93
111
|
# NoMethodError: undefined method `nose' for #<struct Face hair=:blond, eyes=:blue, skin=:awesome>
|
94
112
|
my_face[:nose]
|
95
|
-
# NameError: no member 'nose' in
|
113
|
+
# NameError: no member 'nose' in struct
|
96
114
|
|
97
115
|
|
98
116
|
class PayChecks < Struct.new(:week1, :week2, :week3, :week4)
|
@@ -107,13 +125,45 @@ pay_checks.total
|
|
107
125
|
# => 1245
|
108
126
|
```
|
109
127
|
|
128
|
+
For the following data structures you will need to include `Containers` or prefix every container with it.
|
129
|
+
|
130
|
+
<a name="matrix" />
|
131
|
+
|
132
|
+
## Matrix
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
m = Matrix[[1, 2, 3], [3, 4, 5], [6, 7, 8]]
|
136
|
+
# => Matrix[[1, 2, 3], [3, 4, 5], [6, 7, 8]]
|
137
|
+
m[0,0]
|
138
|
+
# => 1
|
139
|
+
m[1,1]
|
140
|
+
# => 4
|
141
|
+
m.row(2)
|
142
|
+
# => Vector[6, 7, 8]
|
143
|
+
m.column(1)
|
144
|
+
# => Vector[2, 4, 7]
|
145
|
+
```
|
146
|
+
|
147
|
+
<a name="set" />
|
148
|
+
|
149
|
+
## Set
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
s = Set.new
|
153
|
+
# => #<Set: {}>
|
154
|
+
s << :a
|
155
|
+
# => #<Set: {:a}>
|
156
|
+
s << :a
|
157
|
+
# => #<Set: {:a}>
|
158
|
+
s << :b
|
159
|
+
# => #<Set: {:a, :b}>
|
160
|
+
```
|
161
|
+
|
110
162
|
<a name="openstruct" />
|
111
163
|
|
112
164
|
## OpenStruct
|
113
165
|
|
114
166
|
```ruby
|
115
|
-
require 'ostruct'
|
116
|
-
|
117
167
|
x = OpenStruct.new
|
118
168
|
# => #<OpenStruct>
|
119
169
|
|
@@ -137,9 +187,7 @@ x[:b] = 123
|
|
137
187
|
# => 123
|
138
188
|
x
|
139
189
|
# => #<OpenStruct a=0, b=123>
|
140
|
-
```
|
141
|
-
|
142
|
-
For the following datastructures you will need to include `Containers` or prefix every container with it.
|
190
|
+
```
|
143
191
|
|
144
192
|
<a name="tuple" />
|
145
193
|
|
@@ -241,4 +289,4 @@ Writer.file("b", a, line_sep: "\n", col_sep: ' ', mapper: ->x {"0,#{x}"})
|
|
241
289
|
|
242
290
|
* https://github.com/kumar91gopi/Algorithms-and-Data-Structures-in-Ruby/
|
243
291
|
* https://github.com/sagivo/algorithms
|
244
|
-
* https://github.com/SciRuby/
|
292
|
+
* https://github.com/SciRuby/
|
data/lib/containers/tuple.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Containers
|
2
2
|
class Tuple
|
3
|
+
include Enumerable
|
3
4
|
@elements = []
|
4
5
|
def self.[](*elements)
|
5
6
|
new(elements)
|
@@ -13,8 +14,8 @@ module Containers
|
|
13
14
|
@elements[idx]
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
@elements.
|
17
|
+
def each(&block)
|
18
|
+
@elements.each(&block)
|
18
19
|
end
|
19
20
|
|
20
21
|
def to_s
|
data/lib/victory/version.rb
CHANGED
data/lib/victory.rb
CHANGED
@@ -29,3 +29,10 @@ require 'containers/list'
|
|
29
29
|
require 'io_helpers/reader'
|
30
30
|
require 'io_helpers/writer'
|
31
31
|
require 'include_rgl'
|
32
|
+
|
33
|
+
require 'set'
|
34
|
+
Containers::Set = Set
|
35
|
+
require 'ostruct'
|
36
|
+
Containers::OpenStruct = OpenStruct
|
37
|
+
require 'matrix'
|
38
|
+
Containers::Matrix = Matrix
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: victory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnold Szederjesi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|