tasks_gem 0.1.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: 6732a76a919bedc6f51aaeee8d3aeea161f1504afda79215267a1b797c90fcef
4
+ data.tar.gz: 14b23e00033338811349e03ad38162bdd8692bdff014fa5eef7e2009356afcfa
5
+ SHA512:
6
+ metadata.gz: 8a7e217f0b98dc5839c765eb8447b8ebfd27bba59b1db38659f3b2db601ed186a4a5a8f9bbfd37fb5692295a33b7bd2eaf9e61db94d5885259c293d4484166bf
7
+ data.tar.gz: cff1e5e7aeb02f823ec58fe30a2a1e5fc71136ffb8ee43e601da2c65bfd63d4c6d83ff447e0ef60bbd71831b3e10e558b01463bf2fd78eed4c0d8ccfd958c83a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nonalatus@ukr.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in tasks_gem.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tasks_gem (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+ run_tests (0.1.1)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.17)
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+ run_tests (~> 0.1.1)
34
+ tasks_gem!
35
+
36
+ BUNDLED WITH
37
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 marina8915
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Tasks
2
+
3
+ 50 tasks
4
+ Book with tasks http://libgen.io/book/index.php?md5=02CEF7BC8F9FAF75690C1CBE83BE3B70
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'tasks_gem'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install tasks
21
+
22
+ ## Usage
23
+
24
+ Example:
25
+ ```ruby
26
+ require 'tasks_gem'
27
+
28
+ puts Tasks::Task.new.task(num: 2)
29
+ print Tasks::Task.new.number_array(digit: 2356), "\n"
30
+ print Tasks::Task.new.task_1(number_a: 2, number_b: 5), "\n"
31
+ ```
32
+
33
+ All methods:
34
+ ```ruby
35
+ print Tasks::Task.instance_methods(false), "\n"
36
+ ```
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tasks. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the Tasks project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tasks/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tasks_gem"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Tasks
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tasks.rb ADDED
@@ -0,0 +1,503 @@
1
+ require "tasks/version"
2
+
3
+ module Tasks
4
+ class Error < StandardError; end
5
+
6
+ # 50 tasks
7
+ class Task
8
+ def task(num:)
9
+ puts "\n Task #{num}"
10
+ end
11
+
12
+ # number => array, example 234 => [2, 3, 4]
13
+ def number_array(digit:)
14
+ digit.to_s.split('').map(&:to_i)
15
+ end
16
+
17
+ # array of prime numbers
18
+ def array_separators(array:)
19
+ array.select { |x| (1..x).select { |y| (x % y).zero? }.length <= 2 }
20
+ end
21
+
22
+ # matrix n x m
23
+ def new_matrix(n_lines:, m_lines:)
24
+ array = []
25
+ (0..(n_lines - 1)).each do |i|
26
+ array[i] = []
27
+ (0..(m_lines - 1)).each { array[i].push(rand(1..10)) }
28
+ end
29
+ print array, "\n"
30
+ array
31
+ end
32
+
33
+ # if digit not in diapason lower_bound..top_bound enter new n
34
+ def check_digit(digit:, lower_bound: 1, top_bound: 10)
35
+ until (lower_bound..top_bound).cover? digit
36
+ puts 'incorrect value'
37
+ puts 'take again'
38
+ digit = gets.to_i
39
+ end
40
+ digit
41
+ end
42
+
43
+ # array with random digits in diapason lower_bound..y
44
+ def new_array(quantity:, lower_bound: -100, top_bound: 100)
45
+ array = []
46
+ quantity.times { array.push(rand(lower_bound..top_bound)) }
47
+ print "Elements: #{array} \n"
48
+ array
49
+ end
50
+
51
+ # hint when comparing numbers
52
+ def hint(digit1:, digit2:)
53
+ if digit1 > digit2
54
+ 'more than needed'
55
+ elsif digit1 < digit2
56
+ 'less than needed'
57
+ end
58
+ end
59
+
60
+ def task_1(number_a:, number_b:)
61
+ task(num: 1)
62
+ { sum: number_a + number_b,
63
+ difference: number_a - number_b,
64
+ multiplication: number_a * number_b }
65
+ end
66
+
67
+ def task_2(number_a:, number_b:)
68
+ task(num: 2)
69
+ ((number_a.abs - number_b.abs) / (1 + (number_a * number_b).abs)).round(4)
70
+ end
71
+
72
+ def task_3(edge_length:)
73
+ task(num: 3)
74
+ { Volume: edge_length**3, Square: edge_length**2 * 6 }
75
+ end
76
+
77
+ def task_6(cathetus_a:, cathetus_b:)
78
+ task(num: 6)
79
+ { hypotenuse: Math.sqrt(cathetus_a**2 + cathetus_b**2).round(4),
80
+ Square: cathetus_a * cathetus_b / 2 }
81
+ end
82
+
83
+ def task_8(n_corners:, radius:)
84
+ task(num: 8)
85
+ result = 2 * radius * Math.tan(3.14 / n_corners) * n_corners
86
+ result.round(4)
87
+ end
88
+
89
+ def task_9(resistance1:, resistance2:, resistance3:)
90
+ task(num: 9)
91
+ (1 / (1 / resistance1 + 1 / resistance2 + 1 / resistance3)).round(4)
92
+ end
93
+
94
+ def task_10(height:)
95
+ task(num: 10)
96
+ result = Math.sqrt((2 * height) / 9.81)
97
+ result.round(2)
98
+ end
99
+
100
+ def task_12(side_of_triangle:)
101
+ task(num: 12)
102
+ result = Math.sqrt(3) * side_of_triangle / 4 * side_of_triangle**2
103
+ result.round(2)
104
+ end
105
+
106
+ def task_13(pendulum_length:)
107
+ task(num: 13)
108
+ (2 * 3.14 * Math.sqrt(pendulum_length / 9.81)).round(2)
109
+ end
110
+
111
+ def task_15(cathetus_a:, hypotenuse:)
112
+ task(num: 15)
113
+ cathetus_b = Math.sqrt(hypotenuse**2 - cathetus_a**2).round(2)
114
+ { cathetus_b: cathetus_b,
115
+ Square: ((cathetus_a + cathetus_b - hypotenuse) / 2).round(2) }
116
+ end
117
+
118
+ def task_16(circumference:)
119
+ task(num: 16)
120
+ result = Math::PI * Math.sqrt(circumference / (2 * Math::PI))
121
+ result.round(2)
122
+ end
123
+
124
+ def task_24(coordinate_x1:, coordinate_x2:, coordinate_y1:, coordinate_y2:)
125
+ task(num: 24)
126
+ difference_x = coordinate_x1 - coordinate_x2
127
+ difference_y = coordinate_y1 - coordinate_y2
128
+ result = Math.sqrt(difference_x**2 + difference_y**2)
129
+ result.round(2)
130
+ end
131
+
132
+ def task_30(real_num:)
133
+ task(num: 30)
134
+ degree3 = real_num**3
135
+ middle = 2 * real_num + 3 * real_num**2
136
+ res1 = 1 - middle - 4 * degree3
137
+ res2 = 1 + middle + 4 * degree3
138
+ { result1: res1, result2: res2 }
139
+ end
140
+
141
+ def task_33(real_number_x:, real_number_y:)
142
+ task(num: 33)
143
+ array = [real_number_x, real_number_y]
144
+ { min: array.min, max: array.max }
145
+ end
146
+
147
+ def task_34(real_number_x:, real_number_y:, real_number_z:)
148
+ task(num: 34)
149
+ array = [real_number_x, real_number_y, real_number_z]
150
+ { min: array.min, max: array.max }
151
+ end
152
+
153
+ def task_41(natural_number = 3)
154
+ task(num: 41)
155
+ new_array(quantity: natural_number).select { |x| x <= 3 && x >= 1 }
156
+ end
157
+
158
+ def task_43(natural_number = 3)
159
+ task(num: 43)
160
+ array = new_array(quantity: natural_number)
161
+ array2 = array.select { |x| x > 0 }.map { |x| x**2 }
162
+ { array: array, array2: array2 }
163
+ end
164
+
165
+ def task_62(integer:)
166
+ task(num: 62)
167
+ (integer % 2).zero?
168
+ end
169
+
170
+ def task_64(natural_number:)
171
+ task(num: 64)
172
+ natural_number / 100
173
+ end
174
+
175
+ def task_65(natural_number:)
176
+ task(num: 65)
177
+ sum_array = number_array(digit: natural_number).reduce(:+)
178
+ sum_array**3 == natural_number**2
179
+ end
180
+
181
+ def task_67(natural_number:)
182
+ task(num: 67)
183
+ array = number_array(digit: natural_number)
184
+ penultimate_number = array[array.length - 2] if natural_number >= 10
185
+ { digits_number: array.length,
186
+ sum: array.reduce(:+),
187
+ last_digit: array[array.length - 1],
188
+ first_digit: array[0],
189
+ penultimate_number: penultimate_number }
190
+ end
191
+
192
+ def task_182(natural_number:)
193
+ task(num: 182)
194
+ array = new_array(quantity: natural_number)
195
+ array2 = array.select { |elem| (elem % 5).zero? && elem % 7 != 0 }
196
+ { arr_new: array2,
197
+ sum: array2.reduce(:+),
198
+ quantity: array2.length }
199
+ end
200
+
201
+ def task_185(natural_number:)
202
+ task(num: 185)
203
+ array = new_array(quantity: natural_number)
204
+ array2 = array.select { |elem| elem > 0 }
205
+ sum = if array2 != []
206
+ array2.reduce(:+)**2
207
+ else
208
+ 0
209
+ end
210
+ { array: array2, sum: sum }
211
+ end
212
+
213
+ def task_191(natural_number:)
214
+ task(num: 191)
215
+ quantity = 0
216
+ array = new_array(quantity: natural_number)
217
+ array.map! do |elem|
218
+ quantity += 1 if elem > 7
219
+ elem > 7 ? 7 : elem
220
+ end
221
+ { array: array, quantity: quantity }
222
+ end
223
+
224
+ def task_205(natural_number:)
225
+ task(num: 205)
226
+ array = new_array(quantity: natural_number)
227
+ { array: array,
228
+ max: array.map(&:abs).max,
229
+ sum: array.map { |x| x * x }.reduce(:+) }
230
+ end
231
+
232
+ def task_207(natural_number:)
233
+ task(num: 207)
234
+ arr = number_array(digit: natural_number).delete_if do |x|
235
+ x.zero? || x == 5
236
+ end
237
+ arr.join.to_i
238
+ end
239
+
240
+ def task_224(natural_number:)
241
+ task(num: 224)
242
+ (1..natural_number).select { |x| (natural_number % x).zero? }
243
+ end
244
+
245
+ def task_225(natural_number:)
246
+ task(num: 225)
247
+ (1..natural_number).select do |x|
248
+ (natural_number % x**2).zero? && natural_number % x**3 != 0
249
+ end
250
+ end
251
+
252
+ def task_230(natural_number:)
253
+ task(num: 230)
254
+ min = 1000
255
+ num_array = new_array(quantity: natural_number)
256
+ num_array.inject do |x, y|
257
+ min = (x - y).abs if (x - y).abs < min
258
+ y
259
+ end
260
+ min
261
+ end
262
+
263
+ def task_272(natural_number = 50)
264
+ task(num: 272)
265
+ precipitation = new_array(quantity: natural_number,
266
+ lower_bound: 1,
267
+ top_bound: 100)
268
+ average = precipitation.reduce(:+) / precipitation.size
269
+ deviation = []
270
+ precipitation.each { |x| deviation.push(x - average) }
271
+ { array: precipitation,
272
+ average: average,
273
+ deviation: deviation }
274
+ end
275
+
276
+ def task_279(natural_number:)
277
+ task(num: 279)
278
+ a = new_array(quantity: natural_number)
279
+ b = new_array(quantity: natural_number).reverse!
280
+ ab = []
281
+ (0..natural_number - 1).each { |i| ab.push(a[i] + b[i]) }
282
+ { array_a: a, array_b: b, array_ab: ab }
283
+ end
284
+
285
+ def task_302(natural_number:)
286
+ task(num: 302)
287
+ number = number_array(digit: natural_number)
288
+ number.uniq!
289
+ number.length
290
+ end
291
+
292
+ def task_317(natural_number = 10)
293
+ task(num: 317)
294
+ array = new_array(quantity: natural_number)
295
+ sum_array = 0
296
+ (0..natural_number - 1).each { |i| sum_array += array[i]**(i + 1) }
297
+ end
298
+
299
+ def task_325(natural_number:)
300
+ task(num: 325)
301
+ separators = (1..natural_number).select { |x| (natural_number % x).zero? }
302
+ array_separators(array: separators)
303
+ end
304
+
305
+ def task_328(lower_bound = 1, top_bound = 100)
306
+ task(num: 328)
307
+ array_separators(array: (lower_bound..top_bound))
308
+ end
309
+
310
+ def task_536(natural_number:)
311
+ task(num: 536)
312
+ array = new_array(quantity: natural_number)
313
+ { array: array, identical_elements: array != array.uniq }
314
+ end
315
+
316
+ def task_555(natural_number:)
317
+ task(num: 555)
318
+ puts 'pascals triangle'
319
+ a = []
320
+ (0..natural_number - 1).each do |i|
321
+ a[i] = []
322
+ a[i].push(1)
323
+ if i > 0
324
+ (0..a[i - 1].size - 2).each do |j|
325
+ a[i].unshift(a[i - 1][j] + a[i - 1][j + 1])
326
+ end
327
+ a[i].unshift(1)
328
+ end
329
+ print a[i], "\n"
330
+ end
331
+ a
332
+ end
333
+
334
+ def task_561(natural_number:)
335
+ task(num: 561)
336
+ new_array = []
337
+ (1..natural_number).each do |s|
338
+ array = number_array(digit: s * s)
339
+ if array.last(number_array(digit: s).size).join.to_i == s
340
+ new_array.push(s)
341
+ end
342
+ end
343
+ new_array
344
+ end
345
+
346
+ def task_606(side_a:, side_b:, side_c:, side_d:)
347
+ task(num: 606)
348
+ rectangle = [side_a, side_b, side_c, side_d]
349
+ sum_rectangle = rectangle.reduce(:+)
350
+ rectangle_flag = true
351
+ (0..3).each do |i|
352
+ rectangle_flag = false if (sum_rectangle - rectangle[i]) < rectangle[i]
353
+ end
354
+ rectangle_flag
355
+ end
356
+
357
+ def task_697(natural_number1:, natural_number2:, natural_number3:)
358
+ task(num: 697)
359
+ matrix_a = Matrix.rows(new_matrix(n_lines: natural_number1,
360
+ m_lines: natural_number2))
361
+ matrix_b = Matrix.rows(new_matrix(n_lines: natural_number2,
362
+ m_lines: natural_number3))
363
+ { matrix_a: matrix_a,
364
+ matrix_b: matrix_b,
365
+ result: matrix_a * matrix_b }
366
+ end
367
+
368
+ def task_698(natural_number:)
369
+ task(num: 698)
370
+ matrix = Matrix.rows(new_matrix(n_lines: natural_number,
371
+ m_lines: natural_number))
372
+ { matrix: matrix, result: matrix**2 }
373
+ end
374
+
375
+ def task_699(natural_number:)
376
+ task(num: 699)
377
+ matrix_a = Matrix.rows(new_matrix(n_lines: natural_number,
378
+ m_lines: natural_number))
379
+ matrix_b = Matrix.rows(new_matrix(n_lines: natural_number,
380
+ m_lines: natural_number))
381
+ result = matrix_a * matrix_b - matrix_b * matrix_a
382
+ { matrix_a: matrix_a,
383
+ matrix_b: matrix_b,
384
+ result: result }
385
+ end
386
+
387
+ def task_704(natural_number:)
388
+ task(num: 704)
389
+ matrix_a = Matrix.rows(new_matrix(n_lines: natural_number,
390
+ m_lines: natural_number))
391
+ matrix_b = Matrix.rows(new_matrix(n_lines: natural_number,
392
+ m_lines: natural_number))
393
+ matrix_c = Matrix.rows(new_matrix(n_lines: natural_number,
394
+ m_lines: natural_number))
395
+ { matrix_a: matrix_a, matrix_b: matrix_b,
396
+ matrix_c: matrix_c, result: (matrix_a + matrix_b) * matrix_c }
397
+ end
398
+
399
+ def task_710(natural_number1:, natural_number2:)
400
+ task(num: 710)
401
+ m = Matrix.rows(new_matrix(n_lines: natural_number1,
402
+ m_lines: natural_number2))
403
+ m.transpose
404
+ end
405
+
406
+ def task_822(year:)
407
+ task(num: 822)
408
+ (year % 4).zero? ? '366 days' : '365 days'
409
+ end
410
+
411
+ def task_823(year1:, year2:)
412
+ task(num: 823)
413
+ leap_years = 0
414
+ (year1..year2).each { |y| leap_years += 1 if (y % 4).zero? }
415
+ leap_years
416
+ end
417
+
418
+ def task_831(year:)
419
+ task(num: 831)
420
+ october = Time.mktime(year, 10, 1)
421
+ day1 = october.wday
422
+ if day1 < 7
423
+ day = 7 - day1
424
+ Time.mktime(year, 10, day + 1)
425
+ else
426
+ Time.mktime(year, 10, day1)
427
+ end
428
+ end
429
+
430
+ def task_986
431
+ task(num: 986)
432
+ digit = rand(0..9)
433
+ digit_user = ''
434
+ 3.times do
435
+ puts 'Guess the digit (0..9)'
436
+ digit_user = check_digit(digit: gets.to_i, lower_bound: 0, top_bound: 9)
437
+ break if digit_user == digit
438
+
439
+ puts hint(digit1: digit_user, digit2: digit)
440
+ end
441
+ puts digit_user != digit ? "You did not guess #{digit}" : 'Right you are!'
442
+ end
443
+
444
+ # select horse, task 988
445
+ def select_horse
446
+ puts horses = { 1 => 'Watercolor', 2 => 'Alpha', 3 => 'Gallop' }
447
+ puts 'Select horses (1..3)'
448
+ horse_num = check_digit(digit: gets.to_i, lower_bound: 1, top_bound: 3)
449
+ puts horses[horse_num]
450
+ horse_num
451
+ end
452
+
453
+ # place of the horse, task 988
454
+ def horses_num(run:, horse_num:)
455
+ run.map! { |x| x + rand(1..100) }
456
+ text = if run[horse_num - 1] == run.max
457
+ 'First'
458
+ elsif run[horse_num - 1] == run.min
459
+ 'Last'
460
+ else
461
+ 'Second'
462
+ end
463
+ puts text
464
+ run
465
+ end
466
+
467
+ def task_988
468
+ task(num: 988)
469
+ horse_num = select_horse
470
+ finish = 500
471
+ horses_run = []
472
+ 3.times { horses_run.push(rand(1..100)) }
473
+ while horses_run.max < finish
474
+ horses_run = horses_num(run: horses_run, horse_num: horse_num)
475
+ end
476
+ puts horses_run[horse_num - 1] >= finish ? 'Victory!' : 'Try again.'
477
+ end
478
+
479
+ # result game 100 matches
480
+ def matches_result(first:, second:)
481
+ if first > second
482
+ 'First is won'
483
+ elsif first == second
484
+ 'Won friendship'
485
+ else
486
+ 'Second is won'
487
+ end
488
+ end
489
+
490
+ def task_1009
491
+ puts 'Game - 100 matches \n must take from 1 to 10 matches'
492
+ first_player = 0
493
+ second_player = 0
494
+ until first_player >= 100 || second_player >= 100
495
+ puts 'first player'
496
+ first_player += check_digit(digit: gets.to_i)
497
+ puts 'second player'
498
+ second_player += check_digit(digit: gets.to_i)
499
+ end
500
+ puts matches_result(first: first_player, second: second_player)
501
+ end
502
+ end
503
+ end
data/tasks-0.1.0.gem ADDED
Binary file
data/tasks.gemspec ADDED
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tasks/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tasks_gem"
8
+ spec.version = Tasks::VERSION
9
+ spec.authors = ["marina8915"]
10
+ spec.email = ["nonalatus@ukr.net"]
11
+
12
+ spec.summary = %q{50 tasks}
13
+ spec.homepage = "https://github.com/marina8915/tasks_gem"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "run_tests", "~> 0.1.1"
29
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tasks_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - marina8915
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: run_tests
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ description:
70
+ email:
71
+ - nonalatus@ukr.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/tasks.rb
88
+ - lib/tasks/version.rb
89
+ - tasks-0.1.0.gem
90
+ - tasks.gemspec
91
+ homepage: https://github.com/marina8915/tasks_gem
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: 50 tasks
115
+ test_files: []