tasks_gem 0.1.4 → 0.1.5
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 +4 -4
- data/{.gitignore → .gitignire} +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +11 -5
- data/lib/tasks/version.rb +1 -1
- data/lib/tasks.rb +435 -416
- data/tasks.gemspec +1 -1
- metadata +5 -7
- data/.rspec +0 -3
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 168e34586ab652866a9102ea619046db0e38d9f9b9a996607d73ae2502074f12
|
4
|
+
data.tar.gz: bdf7b08378712569fb97bf230bbbb044cadafdc731e5c72b851b58e35239b657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa24c7c8e2906722c08adb91a035d1438ea954e5d839477352b250d0ec89fda81d1680412d8ee81890cda5ec74245aece610e09384a5c2d9d871944ee8879195
|
7
|
+
data.tar.gz: ec2dd14ca07afb7dc4f6fa639c036f64fd7cabf745df29a1be6d911cc7fd65ff5b2da5551f3b5c6390a25902093739be1228b6dae7a24d9b28d307404025ec68
|
data/{.gitignore → .gitignire}
RENAMED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tasks_gem (0.1.
|
5
|
-
run_tests (~> 0.1.
|
4
|
+
tasks_gem (0.1.5)
|
5
|
+
run_tests (~> 0.1.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
23
23
|
rspec-support (~> 3.8.0)
|
24
24
|
rspec-support (3.8.0)
|
25
|
-
run_tests (0.1.
|
25
|
+
run_tests (0.1.2)
|
26
26
|
|
27
27
|
PLATFORMS
|
28
28
|
ruby
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# tasks_gem
|
2
2
|
|
3
3
|
50 tasks
|
4
|
+
https://rubygems.org/gems/tasks_gem
|
5
|
+
|
4
6
|
Book with tasks http://libgen.io/book/index.php?md5=02CEF7BC8F9FAF75690C1CBE83BE3B70
|
5
7
|
|
6
8
|
## Installation
|
@@ -25,15 +27,19 @@ Example:
|
|
25
27
|
```ruby
|
26
28
|
require 'tasks'
|
27
29
|
|
28
|
-
|
29
|
-
print Tasks::Task.
|
30
|
-
print Tasks::Task.new.task_1(number_a: 2, number_b: 5), "\n"
|
30
|
+
print Tasks::Task.number_array(digit: 2356), "\n"
|
31
|
+
print Tasks::Task.task_1(number_a: 2, number_b: 5), "\n"
|
31
32
|
```
|
32
33
|
|
33
34
|
All methods:
|
34
35
|
```ruby
|
35
|
-
print Tasks::Task.
|
36
|
+
print Tasks::Task.methods(false), "\n"
|
36
37
|
```
|
38
|
+
## Dependencies:
|
39
|
+
|
40
|
+
run_tests ~> 0.1.1
|
41
|
+
https://rubygems.org/gems/run_tests
|
42
|
+
|
37
43
|
## Development
|
38
44
|
|
39
45
|
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.
|
data/lib/tasks/version.rb
CHANGED
data/lib/tasks.rb
CHANGED
@@ -1,503 +1,522 @@
|
|
1
1
|
require "tasks/version"
|
2
|
+
require "matrix"
|
2
3
|
|
3
4
|
module Tasks
|
4
5
|
class Error < StandardError; end
|
5
6
|
|
6
7
|
# 50 tasks
|
7
8
|
class Task
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class << self
|
10
|
+
def task(num:)
|
11
|
+
puts "\n Task #{num}"
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# number => array, example 234 => [2, 3, 4]
|
15
|
+
def number_array(digit:)
|
16
|
+
digit.to_s.split('').map(&:to_i)
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
# array of prime numbers
|
20
|
+
def array_separators(array:)
|
21
|
+
array.select { |x| (1..x).select { |y| (x % y).zero? }.length <= 2 }
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# matrix n x m
|
25
|
+
def new_matrix(n_lines:, m_lines:)
|
26
|
+
array = []
|
27
|
+
(0..(n_lines - 1)).each do |i|
|
28
|
+
array[i] = []
|
29
|
+
(0..(m_lines - 1)).each { array[i].push(rand(1..10)) }
|
30
|
+
end
|
31
|
+
print array, "\n"
|
32
|
+
array
|
28
33
|
end
|
29
|
-
print array, "\n"
|
30
|
-
array
|
31
|
-
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
# if digit not in diapason lower_bound..top_bound enter new n
|
36
|
+
def check_digit(digit:, lower_bound: 1, top_bound: 10)
|
37
|
+
until (lower_bound..top_bound).cover? digit
|
38
|
+
puts 'incorrect value'
|
39
|
+
puts 'take again'
|
40
|
+
digit = gets.to_i
|
41
|
+
end
|
42
|
+
digit
|
39
43
|
end
|
40
|
-
digit
|
41
|
-
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
# array with random digits in diapason lower_bound..y
|
46
|
+
def new_array(quantity:, lower_bound: -100, top_bound: 100)
|
47
|
+
array = []
|
48
|
+
quantity.times { array.push(rand(lower_bound..top_bound)) }
|
49
|
+
print "Elements: #{array} \n"
|
50
|
+
array
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
# hint when comparing numbers
|
54
|
+
def hint(digit1:, digit2:)
|
55
|
+
if digit1 > digit2
|
56
|
+
'more than needed'
|
57
|
+
elsif digit1 < digit2
|
58
|
+
'less than needed'
|
59
|
+
end
|
57
60
|
end
|
58
|
-
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def task_1(number_a:, number_b:)
|
63
|
+
task(num: 1)
|
64
|
+
sum = number_a + number_b
|
65
|
+
diff = number_a - number_b
|
66
|
+
mult = number_a * number_b
|
67
|
+
{ sum: sum,
|
68
|
+
difference: diff,
|
69
|
+
multiplication: mult }
|
70
|
+
end
|
66
71
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
72
|
+
def task_2(number_a:, number_b:)
|
73
|
+
task(num: 2)
|
74
|
+
difference = number_a.abs - number_b.abs
|
75
|
+
multiplication = (number_a * number_b).abs
|
76
|
+
(difference / (1 + multiplication)).round(4)
|
77
|
+
end
|
71
78
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
def task_3(edge_length:)
|
80
|
+
task(num: 3)
|
81
|
+
volume = edge_length**3
|
82
|
+
square = edge_length**2 * 6
|
83
|
+
{ Volume: volume, Square: square }
|
84
|
+
end
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
def task_6(cathetus_a:, cathetus_b:)
|
87
|
+
task(num: 6)
|
88
|
+
hypotenuse = Math.sqrt(cathetus_a**2 + cathetus_b**2).round(4)
|
89
|
+
square = cathetus_a * cathetus_b / 2
|
90
|
+
{ hypotenuse: hypotenuse,
|
91
|
+
Square: square }
|
92
|
+
end
|
82
93
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
94
|
+
def task_8(n_corners:, radius:)
|
95
|
+
task(num: 8)
|
96
|
+
result = 2 * radius * Math.tan(3.14 / n_corners) * n_corners
|
97
|
+
result.round(4)
|
98
|
+
end
|
88
99
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
100
|
+
def task_9(resistance1:, resistance2:, resistance3:)
|
101
|
+
task(num: 9)
|
102
|
+
(1 / (1 / resistance1 + 1 / resistance2 + 1 / resistance3)).round(4)
|
103
|
+
end
|
93
104
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
105
|
+
def task_10(height:)
|
106
|
+
task(num: 10)
|
107
|
+
result = Math.sqrt((2 * height) / 9.81)
|
108
|
+
result.round(2)
|
109
|
+
end
|
99
110
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
111
|
+
def task_12(side_of_triangle:)
|
112
|
+
task(num: 12)
|
113
|
+
result = Math.sqrt(3) * side_of_triangle / 4 * side_of_triangle**2
|
114
|
+
result.round(2)
|
115
|
+
end
|
105
116
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
117
|
+
def task_13(pendulum_length:)
|
118
|
+
task(num: 13)
|
119
|
+
(2 * 3.14 * Math.sqrt(pendulum_length / 9.81)).round(2)
|
120
|
+
end
|
110
121
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
122
|
+
def task_15(cathetus_a:, hypotenuse:)
|
123
|
+
task(num: 15)
|
124
|
+
cathetus_b = Math.sqrt(hypotenuse**2 - cathetus_a**2).round(2)
|
125
|
+
square = ((cathetus_a + cathetus_b - hypotenuse) / 2).round(2)
|
126
|
+
{ cathetus_b: cathetus_b,
|
127
|
+
Square: square }
|
128
|
+
end
|
117
129
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
def task_16(circumference:)
|
131
|
+
task(num: 16)
|
132
|
+
result = Math::PI * Math.sqrt(circumference / (2 * Math::PI))
|
133
|
+
result.round(2)
|
134
|
+
end
|
123
135
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
136
|
+
def task_24(coordinate_x1:, coordinate_x2:,
|
137
|
+
coordinate_y1:, coordinate_y2:)
|
138
|
+
task(num: 24)
|
139
|
+
difference_x = coordinate_x1 - coordinate_x2
|
140
|
+
difference_y = coordinate_y1 - coordinate_y2
|
141
|
+
result = Math.sqrt(difference_x**2 + difference_y**2)
|
142
|
+
result.round(2)
|
143
|
+
end
|
131
144
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
145
|
+
def task_30(real_num:)
|
146
|
+
task(num: 30)
|
147
|
+
degree3 = real_num**3
|
148
|
+
middle = 2 * real_num + 3 * real_num**2
|
149
|
+
res1 = 1 - middle - 4 * degree3
|
150
|
+
res2 = 1 + middle + 4 * degree3
|
151
|
+
{ result1: res1, result2: res2 }
|
152
|
+
end
|
140
153
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
154
|
+
def task_33(real_number_x:, real_number_y:)
|
155
|
+
task(num: 33)
|
156
|
+
array = [real_number_x, real_number_y]
|
157
|
+
{ min: array.min, max: array.max }
|
158
|
+
end
|
146
159
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
160
|
+
def task_34(real_number_x:, real_number_y:, real_number_z:)
|
161
|
+
task(num: 34)
|
162
|
+
array = [real_number_x, real_number_y, real_number_z]
|
163
|
+
{ min: array.min, max: array.max }
|
164
|
+
end
|
152
165
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
166
|
+
def task_41(natural_number = 3)
|
167
|
+
task(num: 41)
|
168
|
+
new_array(quantity: natural_number).select { |x| x <= 3 && x >= 1 }
|
169
|
+
end
|
157
170
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
171
|
+
def task_43(natural_number = 3)
|
172
|
+
task(num: 43)
|
173
|
+
array = new_array(quantity: natural_number)
|
174
|
+
array2 = array.select { |x| x > 0 }.map { |x| x**2 }
|
175
|
+
{ array: array, array2: array2 }
|
176
|
+
end
|
164
177
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
178
|
+
def task_62(integer:)
|
179
|
+
task(num: 62)
|
180
|
+
(integer % 2).zero?
|
181
|
+
end
|
169
182
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
183
|
+
def task_64(natural_number:)
|
184
|
+
task(num: 64)
|
185
|
+
natural_number / 100
|
186
|
+
end
|
174
187
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
188
|
+
def task_65(natural_number:)
|
189
|
+
task(num: 65)
|
190
|
+
sum_array = number_array(digit: natural_number).reduce(:+)
|
191
|
+
sum_array**3 == natural_number**2
|
192
|
+
end
|
180
193
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
194
|
+
def task_67(natural_number:)
|
195
|
+
task(num: 67)
|
196
|
+
array = number_array(digit: natural_number)
|
197
|
+
penultimate_number = array[array.length - 2] if natural_number >= 10
|
198
|
+
{ digits_number: array.length,
|
199
|
+
sum: array.reduce(:+),
|
200
|
+
last_digit: array[array.length - 1],
|
201
|
+
first_digit: array[0],
|
202
|
+
penultimate_number: penultimate_number }
|
203
|
+
end
|
191
204
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
205
|
+
def task_182(natural_number:)
|
206
|
+
task(num: 182)
|
207
|
+
array = new_array(quantity: natural_number)
|
208
|
+
array2 = array.select { |elem| (elem % 5).zero? && elem % 7 != 0 }
|
209
|
+
sum = array2.reduce(:+)
|
210
|
+
{ arr_new: array2,
|
211
|
+
sum: sum,
|
212
|
+
quantity: array2.length }
|
213
|
+
end
|
200
214
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
215
|
+
def task_185(natural_number:)
|
216
|
+
task(num: 185)
|
217
|
+
array = new_array(quantity: natural_number)
|
218
|
+
array2 = array.select { |elem| elem > 0 }
|
219
|
+
sum = if array2 != []
|
220
|
+
array2.reduce(:+)**2
|
221
|
+
else
|
222
|
+
0
|
223
|
+
end
|
224
|
+
{ array: array2, sum: sum }
|
225
|
+
end
|
212
226
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
227
|
+
def task_191(natural_number:)
|
228
|
+
task(num: 191)
|
229
|
+
quantity = 0
|
230
|
+
array = new_array(quantity: natural_number)
|
231
|
+
array.map! do |elem|
|
232
|
+
quantity += 1 if elem > 7
|
233
|
+
elem > 7 ? 7 : elem
|
234
|
+
end
|
235
|
+
{ array: array, quantity: quantity }
|
220
236
|
end
|
221
|
-
{ array: array, quantity: quantity }
|
222
|
-
end
|
223
237
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
238
|
+
def task_205(natural_number:)
|
239
|
+
task(num: 205)
|
240
|
+
array = new_array(quantity: natural_number)
|
241
|
+
{ array: array,
|
242
|
+
max: array.map(&:abs).max,
|
243
|
+
sum: array.map { |x| x * x }.reduce(:+) }
|
244
|
+
end
|
231
245
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
246
|
+
def task_207(natural_number:)
|
247
|
+
task(num: 207)
|
248
|
+
arr = number_array(digit: natural_number).delete_if do |x|
|
249
|
+
x.zero? || x == 5
|
250
|
+
end
|
251
|
+
arr.join.to_i
|
236
252
|
end
|
237
|
-
arr.join.to_i
|
238
|
-
end
|
239
253
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
254
|
+
def task_224(natural_number:)
|
255
|
+
task(num: 224)
|
256
|
+
(1..natural_number).select { |x| (natural_number % x).zero? }
|
257
|
+
end
|
244
258
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
259
|
+
def task_225(natural_number:)
|
260
|
+
task(num: 225)
|
261
|
+
(1..natural_number).select do |x|
|
262
|
+
(natural_number % x**2).zero? && natural_number % x**3 != 0
|
263
|
+
end
|
249
264
|
end
|
250
|
-
end
|
251
265
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
266
|
+
def task_230(natural_number:)
|
267
|
+
task(num: 230)
|
268
|
+
min = 1000
|
269
|
+
num_array = new_array(quantity: natural_number)
|
270
|
+
num_array.inject do |x, y|
|
271
|
+
min = (x - y).abs if (x - y).abs < min
|
272
|
+
y
|
273
|
+
end
|
274
|
+
min
|
259
275
|
end
|
260
|
-
min
|
261
|
-
end
|
262
276
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
277
|
+
def task_272(natural_number = 50)
|
278
|
+
task(num: 272)
|
279
|
+
precipitation = new_array(quantity: natural_number,
|
280
|
+
lower_bound: 1,
|
281
|
+
top_bound: 100)
|
282
|
+
average = precipitation.reduce(:+) / precipitation.size
|
283
|
+
deviation = []
|
284
|
+
precipitation.each { |x| deviation.push(x - average) }
|
285
|
+
{ array: precipitation,
|
286
|
+
average: average,
|
287
|
+
deviation: deviation }
|
288
|
+
end
|
275
289
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
290
|
+
def task_279(natural_number:)
|
291
|
+
task(num: 279)
|
292
|
+
a = new_array(quantity: natural_number)
|
293
|
+
b = new_array(quantity: natural_number).reverse!
|
294
|
+
ab = []
|
295
|
+
(0..natural_number - 1).each { |i| ab.push(a[i] + b[i]) }
|
296
|
+
{ array_a: a, array_b: b, array_ab: ab }
|
297
|
+
end
|
284
298
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
299
|
+
def task_302(natural_number:)
|
300
|
+
task(num: 302)
|
301
|
+
number = number_array(digit: natural_number)
|
302
|
+
number.uniq!
|
303
|
+
number.length
|
304
|
+
end
|
291
305
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
306
|
+
def task_317(natural_number = 10)
|
307
|
+
task(num: 317)
|
308
|
+
array = new_array(quantity: natural_number)
|
309
|
+
sum_array = 0
|
310
|
+
(0..natural_number - 1).each { |i| sum_array += array[i]**(i + 1) }
|
311
|
+
end
|
298
312
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
313
|
+
def task_325(natural_number:)
|
314
|
+
task(num: 325)
|
315
|
+
separators = (1..natural_number).select do |x|
|
316
|
+
(natural_number % x).zero?
|
317
|
+
end
|
318
|
+
array_separators(array: separators)
|
319
|
+
end
|
304
320
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
321
|
+
def task_328(lower_bound = 1, top_bound = 100)
|
322
|
+
task(num: 328)
|
323
|
+
array_separators(array: (lower_bound..top_bound))
|
324
|
+
end
|
309
325
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
326
|
+
def task_536(natural_number:)
|
327
|
+
task(num: 536)
|
328
|
+
array = new_array(quantity: natural_number)
|
329
|
+
{ array: array, identical_elements: array != array.uniq }
|
330
|
+
end
|
315
331
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
332
|
+
def task_555(natural_number:)
|
333
|
+
task(num: 555)
|
334
|
+
puts 'pascals triangle'
|
335
|
+
a = []
|
336
|
+
(0..natural_number - 1).each do |i|
|
337
|
+
a[i] = []
|
338
|
+
a[i].push(1)
|
339
|
+
if i > 0
|
340
|
+
(0..a[i - 1].size - 2).each do |j|
|
341
|
+
a[i].unshift(a[i - 1][j] + a[i - 1][j + 1])
|
342
|
+
end
|
343
|
+
a[i].unshift(1)
|
326
344
|
end
|
327
|
-
a[i]
|
345
|
+
print a[i], "\n"
|
328
346
|
end
|
329
|
-
|
347
|
+
a
|
330
348
|
end
|
331
|
-
a
|
332
|
-
end
|
333
349
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
350
|
+
def task_561(natural_number:)
|
351
|
+
task(num: 561)
|
352
|
+
new_array = []
|
353
|
+
(1..natural_number).each do |s|
|
354
|
+
array = number_array(digit: s * s)
|
355
|
+
if array.last(number_array(digit: s).size).join.to_i == s
|
356
|
+
new_array.push(s)
|
357
|
+
end
|
341
358
|
end
|
359
|
+
new_array
|
342
360
|
end
|
343
|
-
new_array
|
344
|
-
end
|
345
361
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
362
|
+
def task_606(side_a:, side_b:, side_c:, side_d:)
|
363
|
+
task(num: 606)
|
364
|
+
rectangle = [side_a, side_b, side_c, side_d]
|
365
|
+
sum = rectangle.reduce(:+)
|
366
|
+
rectangle_flag = true
|
367
|
+
(0..3).each do |i|
|
368
|
+
rectangle_flag = false if (sum - rectangle[i]) < rectangle[i]
|
369
|
+
end
|
370
|
+
rectangle_flag
|
353
371
|
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
372
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
373
|
+
def task_697(natural_number1:, natural_number2:, natural_number3:)
|
374
|
+
task(num: 697)
|
375
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: natural_number1,
|
376
|
+
m_lines: natural_number2))
|
377
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: natural_number2,
|
378
|
+
m_lines: natural_number3))
|
379
|
+
mult = matrix_a * matrix_b
|
380
|
+
{ matrix_a: matrix_a,
|
381
|
+
matrix_b: matrix_b,
|
382
|
+
result: mult }
|
383
|
+
end
|
374
384
|
|
375
|
-
|
376
|
-
|
377
|
-
|
385
|
+
def task_698(natural_number:)
|
386
|
+
task(num: 698)
|
387
|
+
matrix = Matrix.rows(new_matrix(n_lines: natural_number,
|
378
388
|
m_lines: natural_number))
|
379
|
-
|
380
|
-
|
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
|
389
|
+
{ matrix: matrix, result: matrix**2 }
|
390
|
+
end
|
386
391
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
matrix_c: matrix_c, result: (matrix_a + matrix_b) * matrix_c }
|
397
|
-
end
|
392
|
+
def task_699(natural_number:)
|
393
|
+
task(num: 699)
|
394
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: natural_number,
|
395
|
+
m_lines: natural_number))
|
396
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: natural_number,
|
397
|
+
m_lines: natural_number))
|
398
|
+
result = matrix_a * matrix_b - matrix_b * matrix_a
|
399
|
+
{ matrix_a: matrix_a, matrix_b: matrix_b, result: result }
|
400
|
+
end
|
398
401
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
402
|
+
def task_704(natural_number:)
|
403
|
+
task(num: 704)
|
404
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: natural_number,
|
405
|
+
m_lines: natural_number))
|
406
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: natural_number,
|
407
|
+
m_lines: natural_number))
|
408
|
+
matrix_c = Matrix.rows(new_matrix(n_lines: natural_number,
|
409
|
+
m_lines: natural_number))
|
410
|
+
result = (matrix_a + matrix_b) * matrix_c
|
411
|
+
{ matrix_a: matrix_a, matrix_b: matrix_b,
|
412
|
+
matrix_c: matrix_c, result: result }
|
413
|
+
end
|
405
414
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
415
|
+
def task_710(natural_number1:, natural_number2:)
|
416
|
+
task(num: 710)
|
417
|
+
m = Matrix.rows(new_matrix(n_lines: natural_number1,
|
418
|
+
m_lines: natural_number2))
|
419
|
+
m.transpose
|
420
|
+
end
|
410
421
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
leap_years
|
416
|
-
end
|
422
|
+
def task_822(year:)
|
423
|
+
task(num: 822)
|
424
|
+
(year % 4).zero? ? '366 days' : '365 days'
|
425
|
+
end
|
417
426
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
day = 7 - day1
|
424
|
-
Time.mktime(year, 10, day + 1)
|
425
|
-
else
|
426
|
-
Time.mktime(year, 10, day1)
|
427
|
+
def task_823(year1:, year2:)
|
428
|
+
task(num: 823)
|
429
|
+
leap_years = 0
|
430
|
+
(year1..year2).each { |y| leap_years += 1 if (y % 4).zero? }
|
431
|
+
leap_years
|
427
432
|
end
|
428
|
-
end
|
429
433
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
434
|
+
def task_831(year:)
|
435
|
+
task(num: 831)
|
436
|
+
october = Time.mktime(year, 10, 1)
|
437
|
+
day1 = october.wday
|
438
|
+
if day1 < 7
|
439
|
+
day = 7 - day1
|
440
|
+
Time.mktime(year, 10, day + 1)
|
441
|
+
else
|
442
|
+
Time.mktime(year, 10, day1)
|
443
|
+
end
|
444
|
+
end
|
438
445
|
|
439
|
-
|
446
|
+
def task_986
|
447
|
+
task(num: 986)
|
448
|
+
digit = rand(0..9)
|
449
|
+
digit_user = ''
|
450
|
+
3.times do
|
451
|
+
puts 'Guess the digit (0..9)'
|
452
|
+
digit_user = check_digit(digit: gets.to_i,
|
453
|
+
lower_bound: 0,
|
454
|
+
top_bound: 9)
|
455
|
+
break if digit_user == digit
|
456
|
+
|
457
|
+
puts hint(digit1: digit_user, digit2: digit)
|
458
|
+
end
|
459
|
+
puts digit_user != digit ? "Right digit - #{digit}" : 'Right you are!'
|
440
460
|
end
|
441
|
-
puts digit_user != digit ? "You did not guess #{digit}" : 'Right you are!'
|
442
|
-
end
|
443
461
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
462
|
+
# select horse, task 988
|
463
|
+
def select_horse
|
464
|
+
puts horses = { 1 => 'Watercolor', 2 => 'Alpha', 3 => 'Gallop' }
|
465
|
+
puts 'Select horses (1..3)'
|
466
|
+
horse_num = check_digit(digit: gets.to_i, lower_bound: 1, top_bound: 3)
|
467
|
+
puts horses[horse_num]
|
468
|
+
horse_num
|
469
|
+
end
|
452
470
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
471
|
+
# place of the horse, task 988
|
472
|
+
def horses_num(run:, horse_num:)
|
473
|
+
run.map! { |x| x + rand(1..100) }
|
474
|
+
text = if run[horse_num - 1] == run.max
|
475
|
+
'First'
|
476
|
+
elsif run[horse_num - 1] == run.min
|
477
|
+
'Last'
|
478
|
+
else
|
479
|
+
'Second'
|
480
|
+
end
|
481
|
+
puts text
|
482
|
+
run
|
483
|
+
end
|
466
484
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
485
|
+
def task_988
|
486
|
+
task(num: 988)
|
487
|
+
horse_num = select_horse
|
488
|
+
finish = 500
|
489
|
+
horses_run = []
|
490
|
+
3.times { horses_run.push(rand(1..100)) }
|
491
|
+
while horses_run.max < finish
|
492
|
+
horses_run = horses_num(run: horses_run, horse_num: horse_num)
|
493
|
+
end
|
494
|
+
puts horses_run[horse_num - 1] >= finish ? 'Victory!' : 'Try again.'
|
475
495
|
end
|
476
|
-
puts horses_run[horse_num - 1] >= finish ? 'Victory!' : 'Try again.'
|
477
|
-
end
|
478
496
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
497
|
+
# result game 100 matches
|
498
|
+
def matches_result(first:, second:)
|
499
|
+
if first > second
|
500
|
+
'First is won'
|
501
|
+
elsif first == second
|
502
|
+
'Won friendship'
|
503
|
+
else
|
504
|
+
'Second is won'
|
505
|
+
end
|
487
506
|
end
|
488
|
-
end
|
489
507
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
508
|
+
def task_1009
|
509
|
+
puts 'Game - 100 matches \n must take from 1 to 10 matches'
|
510
|
+
first_player = 0
|
511
|
+
second_player = 0
|
512
|
+
until first_player >= 100 || second_player >= 100
|
513
|
+
puts 'first player'
|
514
|
+
first_player += check_digit(digit: gets.to_i)
|
515
|
+
puts 'second player'
|
516
|
+
second_player += check_digit(digit: gets.to_i)
|
517
|
+
end
|
518
|
+
puts matches_result(first: first_player, second: second_player)
|
519
|
+
end
|
501
520
|
end
|
502
521
|
end
|
503
522
|
end
|
data/tasks.gemspec
CHANGED
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.17"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
-
spec.add_dependency "run_tests", "~> 0.1.
|
28
|
+
spec.add_dependency "run_tests", "~> 0.1.2"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tasks_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marina8915
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.2
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.2
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- nonalatus@ukr.net
|
@@ -73,9 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- ".
|
77
|
-
- ".rspec"
|
78
|
-
- ".travis.yml"
|
76
|
+
- ".gitignire"
|
79
77
|
- CODE_OF_CONDUCT.md
|
80
78
|
- Gemfile
|
81
79
|
- Gemfile.lock
|
data/.rspec
DELETED