math_tasks 1.0.1
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 +7 -0
- data/.gitignore +50 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +14 -0
- data/README.md +1 -0
- data/lib/math_tasks.rb +371 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c91e3d76ddf1c0ff57bb750803489adbf4c30dbad62a235e9aeeb790f0ea5b88
|
4
|
+
data.tar.gz: 9736964ba155d0a938b4e3fa2dadddace8ec05e9177e353f1fd659db7ac54216
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2efdfebafc4a872df783daa4c154fa985f0f35ec36289e9d09f35bae11bf68c8aadf771823cda10072aa4a7e5bda5b8dc5845b704e50e6c0637feef18e1fd10
|
7
|
+
data.tar.gz: 4305ff2929427c5735c3b5f7b06325de5c38b8cd0979818b86ee983f9b58e1b76eb5dcd7e8da945297f6143c2298e69b4c9d8bd8e77afa796b389f8b59ad8739
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# MathTasksGem
|
data/lib/math_tasks.rb
ADDED
@@ -0,0 +1,371 @@
|
|
1
|
+
class MathTasks
|
2
|
+
def self.task_1(first_number, second_number)
|
3
|
+
{ sum: first_number + second_number,
|
4
|
+
dif: first_number - second_number,
|
5
|
+
product: first_number * second_number }
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.task_2(first_number, second_number)
|
9
|
+
{ result: (first_number.abs - second_number.abs) / (1 + first_number.abs * second_number.abs) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.task_3(cube_side)
|
13
|
+
{ volume: cube_side**3,
|
14
|
+
surface_area: cube_side**2 }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.task_4(first_number, second_number)
|
18
|
+
{ average: (first_number * second_number) / 2,
|
19
|
+
geometric_mean: Math.sqrt((first_number * second_number)).round(2) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.task_5(first_number, second_number)
|
23
|
+
{ average: (first_number * second_number) / 2,
|
24
|
+
geometric_mean_mod: Math.sqrt((first_number.abs * second_number.abs)).round(2) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.task_6(side1, side2)
|
28
|
+
{ hypotenuse: Math.sqrt(side1**2 + side2**2).round(2),
|
29
|
+
square: side1 * side2 / 2 }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.task_8(number_angle, radius)
|
33
|
+
{ perimeter: (2 * number_angle * radius * Math.tan(Math::PI / number_angle)).round(2) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.task_9(resistor1, resistor2, resistor3)
|
37
|
+
{ total_resistance: (1 / (1 / resistor1.to_f + 1 / resistor2.to_f + 1 / resistor3.to_f)).round(2) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.task_10(height)
|
41
|
+
{ time_fall: Math.sqrt(2 * height / 9.8).round(2) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.task_12(side)
|
45
|
+
{ square: (side**2 * Math.sqrt(3) / 4).round(2) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.task_13(length)
|
49
|
+
{ oscillation_period: (2**Math::PI * Math.sqrt(length) / 9.8).round(2) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.task_14(mass1, mass2, distance)
|
53
|
+
{ force_attraction: mass1 * mass2 * 6.67e-11 / distance**2 }
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.task_15(first_leg, hypotenuse)
|
57
|
+
second_leg = Math.sqrt(hypotenuse**2 - first_leg**2).round 2
|
58
|
+
circle_radius = ((first_leg + second_leg - hypotenuse) / 2).round 2
|
59
|
+
{ second_leg: second_leg,
|
60
|
+
circle_radius: circle_radius }
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.task_16(circumference)
|
64
|
+
{ area: (circumference**2 / (Math::PI * 4)).round(2) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.task_17(outer_radius)
|
68
|
+
{ area: (Math::PI * (outer_radius**2) - Math::PI * (20**2)).round(2) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.task_19(v1, v2, a1, a2, s)
|
72
|
+
{ time: ((- (v1 + v2) + Math.sqrt((v1 + v2) * (v1 + v2) + 2 * (a1 + a2) * s)) / (a1 + a2)).round(2) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.task_20(a, d, n)
|
76
|
+
sum = a
|
77
|
+
(0...n).each do |i|
|
78
|
+
sum += d * i
|
79
|
+
end
|
80
|
+
{ sum: sum }
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.task_22(base1, base2, angle)
|
84
|
+
{ square: (((base1 + base2) * ((base1 - base2).abs / 2) * Math.sin(angle * Math::PI / 180) / \
|
85
|
+
Math.cos(angle * Math::PI / 180)) / 2).round(2) }
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.task_24(x1, x2, y1, y2)
|
89
|
+
{ distance: Math.sqrt((x1 - x2)**2 + (y1 - y2)**2).round(2) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.task_25(x1, y1, x2, y2, x3, y3)
|
93
|
+
a = Math.sqrt(Math.sqrt((x2 - x1).abs) + Math.sqrt((y2 - y1).abs))
|
94
|
+
b = Math.sqrt(Math.sqrt((x3 - x2).abs) + Math.sqrt((y3 - y2).abs))
|
95
|
+
c = Math.sqrt(Math.sqrt((x1 - x3).abs) + Math.sqrt((y1 - y3).abs))
|
96
|
+
p = ((a + b + c) / 2).round 2
|
97
|
+
s = Math.sqrt(p * (p - a) * (p - b) * (p - c)).round 2
|
98
|
+
{ perimeter: p,
|
99
|
+
square: s }
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.task_26(radius, angle_radian)
|
103
|
+
{ square: (radius * radius * angle_radian / 2).round(2) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.task_27(a, b, c)
|
107
|
+
s = a.to_f + b.to_f + c.to_f
|
108
|
+
x = (a / s * 180).round 2
|
109
|
+
y = (b / s * 180).round 2
|
110
|
+
z = (c / s * 180).round 2
|
111
|
+
{ angle_1: x,
|
112
|
+
angle_2: y,
|
113
|
+
angle_3: z }
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.task_28(number)
|
117
|
+
{ result: 6 + number * (-5 + number * (4 + number * (-3 + 2 * number))) }
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.task_33(first_number, second_number)
|
121
|
+
{ max: first_number > second_number ? first_number : second_number,
|
122
|
+
min: first_number > second_number ? second_number : first_number }
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.task_36(x, y, z)
|
126
|
+
{ result: x < y && y < z ? true : false }
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.task_37(x, y, z)
|
130
|
+
if x >= y && y >= z
|
131
|
+
x *= 2
|
132
|
+
y *= 2
|
133
|
+
z *= 2
|
134
|
+
else
|
135
|
+
x = x.abs
|
136
|
+
y = y.abs
|
137
|
+
z = z.abs
|
138
|
+
end
|
139
|
+
{ x: x,
|
140
|
+
y: y,
|
141
|
+
z: z }
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.task_38(x, y)
|
145
|
+
{ z: x > y ? x - y : y - x + 1 }
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.task_39(x, y)
|
149
|
+
{ result: x > y ? x : [x, y] }
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.task_40(x, y)
|
153
|
+
x = 0 if x <= y
|
154
|
+
{ x: x, y: y }
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.task_41(x, y, z)
|
158
|
+
arr = []
|
159
|
+
arr << x if x >= 1 && x <= 3
|
160
|
+
arr << y if y >= 1 && y <= 3
|
161
|
+
arr << z if z >= 1 && z <= 3
|
162
|
+
{ result: arr }
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.task_42(x, y)
|
166
|
+
if x > y
|
167
|
+
y = (x + y) / 2
|
168
|
+
x = (x + y) * 2
|
169
|
+
else
|
170
|
+
x = (x + y) / 2
|
171
|
+
y = (x + y) * 2
|
172
|
+
end
|
173
|
+
{ x: x, y: y }
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.task_43(x, y, z)
|
177
|
+
x **= 2 if x >= 0
|
178
|
+
y **= 2 if y >= 0
|
179
|
+
z **= 2 if z >= 0
|
180
|
+
{ x: x, y: y, z: z }
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.task_45(a, b, c, d)
|
184
|
+
arr = []
|
185
|
+
arr << a << b << c << d
|
186
|
+
m = arr.max
|
187
|
+
rez = a > b && b > c && c > d
|
188
|
+
if a <= b && b <= c && c <= d
|
189
|
+
a = m
|
190
|
+
b = m
|
191
|
+
c = m
|
192
|
+
d = m
|
193
|
+
elsif !rez
|
194
|
+
a **= 2
|
195
|
+
b **= 2
|
196
|
+
c **= 2
|
197
|
+
d **= 2
|
198
|
+
end
|
199
|
+
{ a: a, b: b, c: c, d: d }
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.task_47(a, b, c)
|
203
|
+
if a < (b + c) && b < (a + c) && c < (a + b)
|
204
|
+
if a == b || b == c || a == c
|
205
|
+
if a == b && b == c && a == c
|
206
|
+
{ result: 'equilateral triangle' }
|
207
|
+
else
|
208
|
+
{ result: 'isosceles triangle' }
|
209
|
+
end
|
210
|
+
else
|
211
|
+
{ result: 'arbitrary triangle' }
|
212
|
+
end
|
213
|
+
else
|
214
|
+
{ result: 'no triangle' }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.task_62(number)
|
219
|
+
{ result: number.even? ? 'even' : 'odd' }
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.task_63(a, b, r, _s)
|
223
|
+
{ result: (a % b == r) || (a % b == r) ? true : false }
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.task_64(x)
|
227
|
+
{ result: (x / 100).to_i }
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.task_65(n)
|
231
|
+
{ result: n**2 == n.to_s.split('').inject(0) { |sum, x| sum + x.to_i } }
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.task_66(k, m, x, y, z)
|
235
|
+
if k < m**2
|
236
|
+
x = x.abs
|
237
|
+
y -= 0.5
|
238
|
+
z -= 0.5
|
239
|
+
elsif k == m**2
|
240
|
+
y = y.abs
|
241
|
+
x -= 0.5
|
242
|
+
z -= 0.5
|
243
|
+
else
|
244
|
+
z = z.abs
|
245
|
+
x -= 0.5
|
246
|
+
y -= 0.5
|
247
|
+
end
|
248
|
+
{ x: x, y: y, z: z }
|
249
|
+
end
|
250
|
+
|
251
|
+
def self.task3_73(first_number, second_number)
|
252
|
+
p ' task 73:'
|
253
|
+
arr = []
|
254
|
+
arr << first_number << second_number
|
255
|
+
if first_number != second_number
|
256
|
+
first_number = arr.max
|
257
|
+
second_number = arr.max
|
258
|
+
else
|
259
|
+
first_number = 0
|
260
|
+
second_number = 0
|
261
|
+
end
|
262
|
+
{ first_number: first_number, second_number: second_number }
|
263
|
+
end
|
264
|
+
|
265
|
+
def self.task_74(age)
|
266
|
+
if age >= 11 && age <= 14
|
267
|
+
word = 'лет'
|
268
|
+
else
|
269
|
+
case age % 10
|
270
|
+
when 1
|
271
|
+
word = 'год'
|
272
|
+
when 2, 3, 4
|
273
|
+
word = 'года'
|
274
|
+
else
|
275
|
+
word = 'лет'
|
276
|
+
end
|
277
|
+
end
|
278
|
+
{ result: age.to_s + ' ' + word }
|
279
|
+
end
|
280
|
+
|
281
|
+
def self.task_87(number1, number2)
|
282
|
+
sum = 0
|
283
|
+
i = 0
|
284
|
+
while number1 > 0 && i < number2
|
285
|
+
sum += number1 % 10
|
286
|
+
number1 /= 10
|
287
|
+
i += 1
|
288
|
+
end
|
289
|
+
{ sum: sum }
|
290
|
+
end
|
291
|
+
|
292
|
+
def self.task_90(m, n)
|
293
|
+
nod = m.gcd(n)
|
294
|
+
{ p: m / nod,
|
295
|
+
q: n / nod }
|
296
|
+
end
|
297
|
+
|
298
|
+
def self.task_107(m)
|
299
|
+
rez = 0
|
300
|
+
i = 0
|
301
|
+
while rez < m
|
302
|
+
i += 1
|
303
|
+
rez = 4**i
|
304
|
+
end
|
305
|
+
{ k: i - 1 }
|
306
|
+
end
|
307
|
+
|
308
|
+
def self.task_108(number)
|
309
|
+
rez = 0
|
310
|
+
i = 0
|
311
|
+
while rez < number
|
312
|
+
i += 1
|
313
|
+
rez = 2**i
|
314
|
+
end
|
315
|
+
{ result: rez }
|
316
|
+
end
|
317
|
+
|
318
|
+
def self.task_109(number)
|
319
|
+
f = 0
|
320
|
+
if number == 1
|
321
|
+
f = 2
|
322
|
+
else
|
323
|
+
t = 1
|
324
|
+
(number..2 * number).each do |i|
|
325
|
+
t *= i
|
326
|
+
end
|
327
|
+
f = f * (number - 1) + t
|
328
|
+
end
|
329
|
+
{ result: f }
|
330
|
+
end
|
331
|
+
|
332
|
+
def self.task_183(p, arr)
|
333
|
+
rez = arr.select { |a| (a.to_i % p.to_i).zero? && (a.to_i != 0) }.inject(1) { |r, a| r * a.to_i }
|
334
|
+
{ result: rez }
|
335
|
+
end
|
336
|
+
|
337
|
+
def self.task_251(str)
|
338
|
+
{ result: str.count('x') }
|
339
|
+
end
|
340
|
+
|
341
|
+
def self.task_252(str)
|
342
|
+
{ counter_plus: str.count('+'),
|
343
|
+
counter_multiple: str.count('*'),
|
344
|
+
counter_all: str.count('+') + str.count('-') + str.count('*') }
|
345
|
+
end
|
346
|
+
|
347
|
+
def self.task_261(str)
|
348
|
+
arr = str.split('')
|
349
|
+
space = 0
|
350
|
+
s = 0
|
351
|
+
rez = 0
|
352
|
+
e = 0
|
353
|
+
arr.each do |a|
|
354
|
+
if a == ' '
|
355
|
+
s += 1
|
356
|
+
else
|
357
|
+
space = s if s > space
|
358
|
+
s = 0
|
359
|
+
end
|
360
|
+
if a == 'e'
|
361
|
+
e += 1
|
362
|
+
else
|
363
|
+
rez = e if e > rez
|
364
|
+
e = 0
|
365
|
+
end
|
366
|
+
end
|
367
|
+
{ number_spaces: space,
|
368
|
+
question: rez >= 5 }
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: math_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladyslav volkov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple gem for some math tasks.
|
14
|
+
email: vladislav.volkov@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- README.md
|
23
|
+
- lib/math_tasks.rb
|
24
|
+
homepage: https://github.com/v-volkov/MathTasksGem
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.7.7
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: MathTasks - Simple gem for some math taks
|
48
|
+
test_files: []
|