tasks_gem 0.1.6 → 0.1.7
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/Gemfile.lock +2 -2
- data/README.md +3 -1
- data/lib/tasks/version.rb +1 -1
- data/lib/tasks.rb +147 -220
- data/tasks_gem-0.1.5.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd37558cf32e19b0958c6fa0685db95695bc0a86bd1b6b0990550cd882fa3fee
|
4
|
+
data.tar.gz: e54c32ec88ef3751f96714c477c1df1699c9d0d19f4f96479cdfd8d2ab15b9b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fe439a7fefbb6c3ca8c97bbce94db15bbaddb745c1c8ad31257e21a0b10c576998a75c03cd888f5573823096cccdcac4d1752d8e89b200a0411ab37947e5f2e
|
7
|
+
data.tar.gz: 8c2918b7802a730d3820153927d3115750d0d1667df0218b508352c690ea66389e8658a763bc3be3f05a450ae4fb2a8c4d781a7f26b4a76a6420164a47569e21
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,9 +35,11 @@ All methods:
|
|
35
35
|
```ruby
|
36
36
|
print Tasks::Task.methods(false), "\n"
|
37
37
|
```
|
38
|
+
Example use: https://github.com/marina8915/tasks-rails
|
39
|
+
|
38
40
|
## Dependencies:
|
39
41
|
|
40
|
-
run_tests ~> 0.1.
|
42
|
+
run_tests ~> 0.1.1
|
41
43
|
https://rubygems.org/gems/run_tests
|
42
44
|
|
43
45
|
## Development
|
data/lib/tasks/version.rb
CHANGED
data/lib/tasks.rb
CHANGED
@@ -7,10 +7,6 @@ module Tasks
|
|
7
7
|
# 50 tasks
|
8
8
|
class Task
|
9
9
|
class << self
|
10
|
-
def task(num:)
|
11
|
-
puts "\n Task #{num}"
|
12
|
-
end
|
13
|
-
|
14
10
|
# number => array, example 234 => [2, 3, 4]
|
15
11
|
def number_array(digit:)
|
16
12
|
digit.to_s.split('').map(&:to_i)
|
@@ -28,7 +24,6 @@ module Tasks
|
|
28
24
|
array[i] = []
|
29
25
|
(0..(m_lines - 1)).each { array[i].push(rand(1..10)) }
|
30
26
|
end
|
31
|
-
print array, "\n"
|
32
27
|
array
|
33
28
|
end
|
34
29
|
|
@@ -46,7 +41,6 @@ module Tasks
|
|
46
41
|
def new_array(quantity:, lower_bound: -100, top_bound: 100)
|
47
42
|
array = []
|
48
43
|
quantity.times { array.push(rand(lower_bound..top_bound)) }
|
49
|
-
print "Elements: #{array} \n"
|
50
44
|
array
|
51
45
|
end
|
52
46
|
|
@@ -59,142 +53,122 @@ module Tasks
|
|
59
53
|
end
|
60
54
|
end
|
61
55
|
|
62
|
-
def task_1(
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
def task_1(a:, b:)
|
57
|
+
sum = a + b
|
58
|
+
diff = a - b
|
59
|
+
mult = a * b
|
60
|
+
{ sum: sum.round(2),
|
61
|
+
difference: diff.round(2),
|
62
|
+
multiplication: mult.round(2)
|
63
|
+
}
|
70
64
|
end
|
71
65
|
|
72
|
-
def task_2(
|
73
|
-
|
74
|
-
|
75
|
-
multiplication = (number_a * number_b).abs
|
66
|
+
def task_2(x:, y:)
|
67
|
+
difference = x.abs - y.abs
|
68
|
+
multiplication = (x * y).abs
|
76
69
|
(difference / (1 + multiplication)).round(4)
|
77
70
|
end
|
78
71
|
|
79
72
|
def task_3(edge_length:)
|
80
|
-
task(num: 3)
|
81
73
|
volume = edge_length**3
|
82
74
|
square = edge_length**2 * 6
|
83
|
-
{ Volume: volume, Square: square }
|
75
|
+
{ Volume: volume.round(2), Square: square.round(2) }
|
84
76
|
end
|
85
77
|
|
86
78
|
def task_6(cathetus_a:, cathetus_b:)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
{ hypotenuse: hypotenuse,
|
91
|
-
Square: square }
|
79
|
+
hypotenuse = Math.sqrt(cathetus_a**2 + cathetus_b**2).round(2)
|
80
|
+
square = (cathetus_a * cathetus_b / 2).round(2)
|
81
|
+
{ hypotenuse: hypotenuse, Square: square }
|
92
82
|
end
|
93
83
|
|
94
84
|
def task_8(n_corners:, radius:)
|
95
|
-
task(num: 8)
|
96
85
|
result = 2 * radius * Math.tan(3.14 / n_corners) * n_corners
|
97
|
-
result.round(4)
|
86
|
+
{ Perimeter: result.round(4) }
|
98
87
|
end
|
99
88
|
|
100
89
|
def task_9(resistance1:, resistance2:, resistance3:)
|
101
|
-
task(num: 9)
|
102
90
|
(1 / (1 / resistance1 + 1 / resistance2 + 1 / resistance3)).round(4)
|
103
91
|
end
|
104
92
|
|
105
93
|
def task_10(height:)
|
106
|
-
task(num: 10)
|
107
94
|
result = Math.sqrt((2 * height) / 9.81)
|
108
|
-
result.round(2)
|
95
|
+
{ time: result.round(2) }
|
109
96
|
end
|
110
97
|
|
111
98
|
def task_12(side_of_triangle:)
|
112
|
-
task(num: 12)
|
113
99
|
result = Math.sqrt(3) * side_of_triangle / 4 * side_of_triangle**2
|
114
|
-
result.round(2)
|
100
|
+
{ Square: result.round(2) }
|
115
101
|
end
|
116
102
|
|
117
103
|
def task_13(pendulum_length:)
|
118
|
-
|
119
|
-
|
104
|
+
result = (2 * 3.14 * Math.sqrt(pendulum_length / 9.81)).round(2)
|
105
|
+
{ period: result }
|
120
106
|
end
|
121
107
|
|
122
108
|
def task_15(cathetus_a:, hypotenuse:)
|
123
|
-
|
124
|
-
cathetus_b = Math.sqrt(hypotenuse**2 - cathetus_a**2).round(2)
|
109
|
+
cathetus_b = Math.sqrt(hypotenuse**2 - cathetus_a**2)
|
125
110
|
square = ((cathetus_a + cathetus_b - hypotenuse) / 2).round(2)
|
126
|
-
{ cathetus_b: cathetus_b,
|
127
|
-
Square: square }
|
111
|
+
{ cathetus_b: cathetus_b.round(2), Square: square }
|
128
112
|
end
|
129
113
|
|
130
114
|
def task_16(circumference:)
|
131
|
-
task(num: 16)
|
132
115
|
result = Math::PI * Math.sqrt(circumference / (2 * Math::PI))
|
133
|
-
result.round(2)
|
116
|
+
{ Square: result.round(2) }
|
134
117
|
end
|
135
118
|
|
136
|
-
def task_24(
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
difference_y = coordinate_y1 - coordinate_y2
|
141
|
-
result = Math.sqrt(difference_x**2 + difference_y**2)
|
119
|
+
def task_24(x1:, x2:, y1:, y2:)
|
120
|
+
diff_x = x1 - x2
|
121
|
+
diff_y = y1 - y2
|
122
|
+
result = Math.sqrt(diff_x**2 + diff_y**2)
|
142
123
|
result.round(2)
|
143
124
|
end
|
144
125
|
|
145
|
-
def task_30(
|
146
|
-
|
147
|
-
|
148
|
-
middle = 2 * real_num + 3 * real_num**2
|
126
|
+
def task_30(x:)
|
127
|
+
degree3 = x**3
|
128
|
+
middle = 2 * x + 3 * x**2
|
149
129
|
res1 = 1 - middle - 4 * degree3
|
150
130
|
res2 = 1 + middle + 4 * degree3
|
151
|
-
{ result1: res1, result2: res2 }
|
131
|
+
{ result1: res1.round(2), result2: res2.round(2) }
|
152
132
|
end
|
153
133
|
|
154
|
-
def task_33(
|
155
|
-
|
156
|
-
array = [real_number_x, real_number_y]
|
134
|
+
def task_33(x:, y:)
|
135
|
+
array = [x, y]
|
157
136
|
{ min: array.min, max: array.max }
|
158
137
|
end
|
159
138
|
|
160
|
-
def task_34(
|
161
|
-
|
162
|
-
array = [real_number_x, real_number_y, real_number_z]
|
139
|
+
def task_34(x:, y:, z:)
|
140
|
+
array = [x, y, z]
|
163
141
|
{ min: array.min, max: array.max }
|
164
142
|
end
|
165
143
|
|
166
|
-
def task_41(
|
167
|
-
|
168
|
-
|
144
|
+
def task_41(x:, y:, z:)
|
145
|
+
array = [x, y, z]
|
146
|
+
array.select { |x| x <= 3 && x >= 1 }
|
169
147
|
end
|
170
148
|
|
171
|
-
def task_43(
|
172
|
-
|
173
|
-
array
|
174
|
-
array2 = array.select { |x| x > 0 }.map { |x| x**2 }
|
175
|
-
{ array: array, array2: array2 }
|
149
|
+
def task_43(x:, y:, z:)
|
150
|
+
array = [x, y, z]
|
151
|
+
array.select { |x| x > 0 }.map { |x| x**2 }
|
176
152
|
end
|
177
153
|
|
178
|
-
def task_62(
|
179
|
-
|
180
|
-
(
|
154
|
+
def task_62(digit:)
|
155
|
+
digit.to_i
|
156
|
+
(digit % 2).zero? ? 'yes' : 'no'
|
181
157
|
end
|
182
158
|
|
183
|
-
def task_64(
|
184
|
-
|
185
|
-
natural_number / 100
|
159
|
+
def task_64(digit:)
|
160
|
+
(digit / 100).to_i
|
186
161
|
end
|
187
162
|
|
188
|
-
def task_65(
|
189
|
-
|
190
|
-
sum_array
|
191
|
-
sum_array**3 == natural_number**2
|
163
|
+
def task_65(digit:)
|
164
|
+
sum_array = number_array(digit: digit).reduce(:+)
|
165
|
+
sum_array**3 == digit**2 ? 'yes' : 'no'
|
192
166
|
end
|
193
167
|
|
194
|
-
def task_67(
|
195
|
-
|
196
|
-
array = number_array(digit:
|
197
|
-
penultimate_number = array[array.length - 2] if
|
168
|
+
def task_67(digit:)
|
169
|
+
digit.to_i
|
170
|
+
array = number_array(digit: digit)
|
171
|
+
penultimate_number = array[array.length - 2] if digit >= 10
|
198
172
|
{ digits_number: array.length,
|
199
173
|
sum: array.reduce(:+),
|
200
174
|
last_digit: array[array.length - 1],
|
@@ -202,19 +176,15 @@ module Tasks
|
|
202
176
|
penultimate_number: penultimate_number }
|
203
177
|
end
|
204
178
|
|
205
|
-
def task_182(
|
206
|
-
|
207
|
-
array = new_array(quantity: natural_number)
|
179
|
+
def task_182(n:)
|
180
|
+
array = new_array(quantity: n.to_i)
|
208
181
|
array2 = array.select { |elem| (elem % 5).zero? && elem % 7 != 0 }
|
209
182
|
sum = array2.reduce(:+)
|
210
|
-
{ arr_new: array2,
|
211
|
-
sum: sum,
|
212
|
-
quantity: array2.length }
|
183
|
+
{ arr_new: array2, sum: sum, quantity: array2.length }
|
213
184
|
end
|
214
185
|
|
215
|
-
def task_185(
|
216
|
-
|
217
|
-
array = new_array(quantity: natural_number)
|
186
|
+
def task_185(n:)
|
187
|
+
array = new_array(quantity: n.to_i)
|
218
188
|
array2 = array.select { |elem| elem > 0 }
|
219
189
|
sum = if array2 != []
|
220
190
|
array2.reduce(:+)**2
|
@@ -224,10 +194,9 @@ module Tasks
|
|
224
194
|
{ array: array2, sum: sum }
|
225
195
|
end
|
226
196
|
|
227
|
-
def task_191(
|
228
|
-
task(num: 191)
|
197
|
+
def task_191(n:)
|
229
198
|
quantity = 0
|
230
|
-
array = new_array(quantity:
|
199
|
+
array = new_array(quantity: n.to_i)
|
231
200
|
array.map! do |elem|
|
232
201
|
quantity += 1 if elem > 7
|
233
202
|
elem > 7 ? 7 : elem
|
@@ -235,38 +204,33 @@ module Tasks
|
|
235
204
|
{ array: array, quantity: quantity }
|
236
205
|
end
|
237
206
|
|
238
|
-
def task_205(
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
sum: array.map { |x| x * x }.reduce(:+) }
|
207
|
+
def task_205(n:)
|
208
|
+
array = new_array(quantity: n.to_i)
|
209
|
+
max = array.map(&:abs).max
|
210
|
+
sum = Math.sqrt(array.map { |x| x * x }.reduce(:+))
|
211
|
+
{ array: array, max: max, sum: sum }
|
244
212
|
end
|
245
213
|
|
246
|
-
def task_207(
|
247
|
-
|
248
|
-
arr = number_array(digit: natural_number).delete_if do |x|
|
214
|
+
def task_207(n:)
|
215
|
+
arr = number_array(digit: n.to_i).delete_if do |x|
|
249
216
|
x.zero? || x == 5
|
250
217
|
end
|
251
218
|
arr.join.to_i
|
252
219
|
end
|
253
220
|
|
254
|
-
def task_224(
|
255
|
-
|
256
|
-
(1..
|
221
|
+
def task_224(n:)
|
222
|
+
n.to_i
|
223
|
+
(1..n).select { |x| (n % x).zero? }
|
257
224
|
end
|
258
225
|
|
259
|
-
def task_225(
|
260
|
-
|
261
|
-
(1..
|
262
|
-
(natural_number % x**2).zero? && natural_number % x**3 != 0
|
263
|
-
end
|
226
|
+
def task_225(n:)
|
227
|
+
n.to_i
|
228
|
+
(1..n).select {|x| (n % x**2).zero? && n % x**3 != 0 }
|
264
229
|
end
|
265
230
|
|
266
|
-
def task_230(
|
267
|
-
task(num: 230)
|
231
|
+
def task_230(n:)
|
268
232
|
min = 1000
|
269
|
-
num_array = new_array(quantity:
|
233
|
+
num_array = new_array(quantity: n.to_i)
|
270
234
|
num_array.inject do |x, y|
|
271
235
|
min = (x - y).abs if (x - y).abs < min
|
272
236
|
y
|
@@ -274,66 +238,59 @@ module Tasks
|
|
274
238
|
min
|
275
239
|
end
|
276
240
|
|
277
|
-
def task_272(
|
278
|
-
|
279
|
-
precipitation = new_array(quantity: natural_number,
|
241
|
+
def task_272(n:)
|
242
|
+
precipitation = new_array(quantity: n.to_i,
|
280
243
|
lower_bound: 1,
|
281
244
|
top_bound: 100)
|
282
245
|
average = precipitation.reduce(:+) / precipitation.size
|
283
246
|
deviation = []
|
284
247
|
precipitation.each { |x| deviation.push(x - average) }
|
285
|
-
{
|
286
|
-
average: average,
|
287
|
-
deviation: deviation }
|
248
|
+
{ precipitation: precipitation, average: average, deviation: deviation }
|
288
249
|
end
|
289
250
|
|
290
|
-
def task_279(
|
291
|
-
|
292
|
-
a = new_array(quantity:
|
293
|
-
b = new_array(quantity:
|
251
|
+
def task_279(n:)
|
252
|
+
n.to_i
|
253
|
+
a = new_array(quantity: n)
|
254
|
+
b = new_array(quantity: n).reverse!
|
294
255
|
ab = []
|
295
|
-
(0..
|
256
|
+
(0..n - 1).each { |i| ab.push(a[i] + b[i]) }
|
296
257
|
{ array_a: a, array_b: b, array_ab: ab }
|
297
258
|
end
|
298
259
|
|
299
|
-
def task_302(
|
300
|
-
|
301
|
-
number = number_array(digit: natural_number)
|
260
|
+
def task_302(n:)
|
261
|
+
number = number_array(digit: n.to_i)
|
302
262
|
number.uniq!
|
303
263
|
number.length
|
304
264
|
end
|
305
265
|
|
306
|
-
def task_317(
|
307
|
-
|
308
|
-
array = new_array(quantity: natural_number)
|
266
|
+
def task_317(n:)
|
267
|
+
array = new_array(quantity: n.to_i)
|
309
268
|
sum_array = 0
|
310
|
-
(0..
|
269
|
+
(0..n - 1).each { |i| sum_array += array[i]**(i + 1) }
|
311
270
|
end
|
312
271
|
|
313
|
-
def task_325(
|
314
|
-
|
315
|
-
separators = (1..
|
316
|
-
(
|
272
|
+
def task_325(n:)
|
273
|
+
n.to_i
|
274
|
+
separators = (1..n).select do |x|
|
275
|
+
(n % x).zero?
|
317
276
|
end
|
318
277
|
array_separators(array: separators)
|
319
278
|
end
|
320
279
|
|
321
|
-
def task_328
|
322
|
-
|
323
|
-
array_separators(array: (lower_bound..top_bound))
|
280
|
+
def task_328
|
281
|
+
array_separators(array: (1..100))
|
324
282
|
end
|
325
283
|
|
326
|
-
def task_536(
|
327
|
-
|
328
|
-
|
329
|
-
{ array: array, identical_elements:
|
284
|
+
def task_536(n:)
|
285
|
+
array = new_array(quantity: n.to_i)
|
286
|
+
result = array != array.uniq ? 'yes' : 'no'
|
287
|
+
{ array: array, identical_elements: result }
|
330
288
|
end
|
331
289
|
|
332
|
-
def task_555(
|
333
|
-
|
334
|
-
puts 'pascals triangle'
|
290
|
+
def task_555(n:)
|
291
|
+
n.to_i
|
335
292
|
a = []
|
336
|
-
(0..
|
293
|
+
(0..n - 1).each do |i|
|
337
294
|
a[i] = []
|
338
295
|
a[i].push(1)
|
339
296
|
if i > 0
|
@@ -342,15 +299,14 @@ module Tasks
|
|
342
299
|
end
|
343
300
|
a[i].unshift(1)
|
344
301
|
end
|
345
|
-
print a[i], "\n"
|
346
302
|
end
|
347
303
|
a
|
348
304
|
end
|
349
305
|
|
350
|
-
def task_561(
|
351
|
-
|
306
|
+
def task_561(n:)
|
307
|
+
n.to_i
|
352
308
|
new_array = []
|
353
|
-
(1..
|
309
|
+
(1..n).each do |s|
|
354
310
|
array = number_array(digit: s * s)
|
355
311
|
if array.last(number_array(digit: s).size).join.to_i == s
|
356
312
|
new_array.push(s)
|
@@ -359,113 +315,85 @@ module Tasks
|
|
359
315
|
new_array
|
360
316
|
end
|
361
317
|
|
362
|
-
def task_606(
|
363
|
-
|
364
|
-
rectangle = [side_a, side_b, side_c, side_d]
|
318
|
+
def task_606(a:, b:, c:, d:)
|
319
|
+
rectangle = [a, b, c, d]
|
365
320
|
sum = rectangle.reduce(:+)
|
366
321
|
rectangle_flag = true
|
367
322
|
(0..3).each do |i|
|
368
323
|
rectangle_flag = false if (sum - rectangle[i]) < rectangle[i]
|
369
324
|
end
|
370
|
-
rectangle_flag
|
325
|
+
rectangle_flag ? 'yes' : 'no'
|
371
326
|
end
|
372
327
|
|
373
|
-
def task_697(
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
328
|
+
def task_697(k:, m:, l:)
|
329
|
+
k.to_i
|
330
|
+
m.to_i
|
331
|
+
l.to_i
|
332
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: k, m_lines: m))
|
333
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: m, m_lines: l))
|
379
334
|
mult = matrix_a * matrix_b
|
380
|
-
{ matrix_a: matrix_a,
|
381
|
-
matrix_b: matrix_b,
|
382
|
-
result: mult }
|
335
|
+
{ matrix_a: matrix_a, matrix_b: matrix_b, result: mult }
|
383
336
|
end
|
384
337
|
|
385
|
-
def task_698(
|
386
|
-
|
387
|
-
matrix = Matrix.rows(new_matrix(n_lines:
|
388
|
-
m_lines: natural_number))
|
338
|
+
def task_698(n:)
|
339
|
+
n.to_i
|
340
|
+
matrix = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
389
341
|
{ matrix: matrix, result: matrix**2 }
|
390
342
|
end
|
391
343
|
|
392
|
-
def task_699(
|
393
|
-
|
394
|
-
matrix_a = Matrix.rows(new_matrix(n_lines:
|
395
|
-
|
396
|
-
matrix_b = Matrix.rows(new_matrix(n_lines: natural_number,
|
397
|
-
m_lines: natural_number))
|
344
|
+
def task_699(n:)
|
345
|
+
n.to_i
|
346
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
347
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
398
348
|
result = matrix_a * matrix_b - matrix_b * matrix_a
|
399
349
|
{ matrix_a: matrix_a, matrix_b: matrix_b, result: result }
|
400
350
|
end
|
401
351
|
|
402
|
-
def task_704(
|
403
|
-
|
404
|
-
matrix_a = Matrix.rows(new_matrix(n_lines:
|
405
|
-
|
406
|
-
|
407
|
-
m_lines: natural_number))
|
408
|
-
matrix_c = Matrix.rows(new_matrix(n_lines: natural_number,
|
409
|
-
m_lines: natural_number))
|
352
|
+
def task_704(n:)
|
353
|
+
n.to_i
|
354
|
+
matrix_a = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
355
|
+
matrix_b = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
356
|
+
matrix_c = Matrix.rows(new_matrix(n_lines: n, m_lines: n))
|
410
357
|
result = (matrix_a + matrix_b) * matrix_c
|
411
358
|
{ matrix_a: matrix_a, matrix_b: matrix_b,
|
412
359
|
matrix_c: matrix_c, result: result }
|
413
360
|
end
|
414
361
|
|
415
|
-
def task_710(
|
416
|
-
|
417
|
-
|
418
|
-
m_lines: natural_number2))
|
419
|
-
m.transpose
|
362
|
+
def task_710(m:, n:)
|
363
|
+
matrix = Matrix.rows(new_matrix(n_lines: m.to_i, m_lines: n.to_i))
|
364
|
+
matrix.transpose
|
420
365
|
end
|
421
366
|
|
422
367
|
def task_822(year:)
|
423
|
-
|
368
|
+
year.to_i
|
424
369
|
(year % 4).zero? ? '366 days' : '365 days'
|
425
370
|
end
|
426
371
|
|
427
|
-
def task_823(
|
428
|
-
|
372
|
+
def task_823(n:, m:)
|
373
|
+
n.to_i
|
374
|
+
m.to_i
|
429
375
|
leap_years = 0
|
430
|
-
(
|
376
|
+
(n..m).each { |y| leap_years += 1 if (y % 4).zero? }
|
431
377
|
leap_years
|
432
378
|
end
|
433
379
|
|
434
|
-
def task_831(
|
435
|
-
|
436
|
-
october = Time.mktime(
|
380
|
+
def task_831(n:)
|
381
|
+
n.to_i
|
382
|
+
october = Time.mktime(n, 10, 1)
|
437
383
|
day1 = october.wday
|
438
384
|
if day1 < 7
|
439
385
|
day = 7 - day1
|
440
|
-
Time.mktime(
|
386
|
+
Time.mktime(n, 10, day + 1)
|
441
387
|
else
|
442
|
-
Time.mktime(
|
388
|
+
Time.mktime(n, 10, day1)
|
443
389
|
end
|
444
390
|
end
|
445
391
|
|
446
|
-
def task_986
|
447
|
-
|
392
|
+
def task_986(n:)
|
393
|
+
n.to_i
|
448
394
|
digit = rand(0..9)
|
449
|
-
digit_user =
|
450
|
-
|
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!'
|
460
|
-
end
|
461
|
-
|
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
|
395
|
+
digit_user = check_digit(digit: n, lower_bound: 0, top_bound: 9)
|
396
|
+
digit_user != digit ? hint(digit1: digit_user, digit2: digit) : 'Right you are!'
|
469
397
|
end
|
470
398
|
|
471
399
|
# place of the horse, task 988
|
@@ -482,16 +410,15 @@ module Tasks
|
|
482
410
|
run
|
483
411
|
end
|
484
412
|
|
485
|
-
def task_988
|
486
|
-
|
487
|
-
horse_num = select_horse
|
413
|
+
def task_988(horse_num:)
|
414
|
+
horse = (1..3).include? horse_num.to_i ? horse_num : 1
|
488
415
|
finish = 500
|
489
416
|
horses_run = []
|
490
417
|
3.times { horses_run.push(rand(1..100)) }
|
491
418
|
while horses_run.max < finish
|
492
|
-
horses_run = horses_num(run: horses_run, horse_num:
|
419
|
+
horses_run = horses_num(run: horses_run, horse_num: horse)
|
493
420
|
end
|
494
|
-
|
421
|
+
horses_run[horse_num - 1] >= finish ? 'Victory!' : 'Try again.'
|
495
422
|
end
|
496
423
|
|
497
424
|
# result game 100 matches
|
data/tasks_gem-0.1.5.gem
ADDED
Binary file
|
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.7
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- tasks.gemspec
|
88
88
|
- tasks_gem-0.1.0.gem
|
89
89
|
- tasks_gem-0.1.4.gem
|
90
|
+
- tasks_gem-0.1.5.gem
|
90
91
|
homepage: https://github.com/marina8915/tasks_gem
|
91
92
|
licenses:
|
92
93
|
- MIT
|