class MathTasks
Constants
- THE_TASK_1
- THE_TASK_10
- THE_TASK_107
- THE_TASK_108
- THE_TASK_109
- THE_TASK_12
- THE_TASK_13
- THE_TASK_14
- THE_TASK_15
- THE_TASK_16
- THE_TASK_17
- THE_TASK_183
- THE_TASK_19
- THE_TASK_2
- THE_TASK_20
- THE_TASK_22
- THE_TASK_24
- THE_TASK_25
- THE_TASK_251
- THE_TASK_252
- THE_TASK_26
- THE_TASK_261
- THE_TASK_27
- THE_TASK_28
- THE_TASK_3
- THE_TASK_33
- THE_TASK_36
- THE_TASK_37
- THE_TASK_38
- THE_TASK_39
- THE_TASK_4
- THE_TASK_40
- THE_TASK_41
- THE_TASK_42
- THE_TASK_43
- THE_TASK_45
- THE_TASK_47
- THE_TASK_5
- THE_TASK_6
- THE_TASK_62
- THE_TASK_63
- THE_TASK_64
- THE_TASK_65
- THE_TASK_66
- THE_TASK_73
- THE_TASK_74
- THE_TASK_8
- THE_TASK_87
- THE_TASK_9
- THE_TASK_90
Public Class Methods
task_1(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 64 def task_1(first_number, second_number) { sum: first_number + second_number, dif: first_number - second_number, product: first_number * second_number } end
task_10(height)
click to toggle source
# File lib/math_tasks.rb, line 102 def task_10(height) { time_fall: Math.sqrt(2 * height / 9.8).round(2) } end
task_107(m)
click to toggle source
# File lib/math_tasks.rb, line 360 def task_107(m) rez = 0 i = 0 while rez < m i += 1 rez = 4**i end { k: i - 1 } end
task_108(number)
click to toggle source
# File lib/math_tasks.rb, line 370 def self.task_108(number) rez = 0 i = 0 while rez < number i += 1 rez = 2**i end { result: rez } end
task_109(number)
click to toggle source
# File lib/math_tasks.rb, line 380 def task_109(number) f = 0 if number == 1 f = 2 else t = 1 (number..2 * number).each do |i| t *= i end f = f * (number - 1) + t end { result: f } end
task_12(side)
click to toggle source
# File lib/math_tasks.rb, line 106 def task_12(side) { square: (side**2 * Math.sqrt(3) / 4).round(2) } end
task_13(length)
click to toggle source
# File lib/math_tasks.rb, line 110 def task_13(length) { oscillation_period: (2**Math::PI * Math.sqrt(length) / 9.8).round(2) } end
task_14(mass1, mass2, distance)
click to toggle source
# File lib/math_tasks.rb, line 114 def task_14(mass1, mass2, distance) { force_attraction: mass1 * mass2 * 6.67e-11 / distance**2 } end
task_15(first_leg, hypotenuse)
click to toggle source
# File lib/math_tasks.rb, line 118 def task_15(first_leg, hypotenuse) second_leg = Math.sqrt(hypotenuse**2 - first_leg**2).round 2 circle_radius = ((first_leg + second_leg - hypotenuse) / 2).round 2 { second_leg: second_leg, circle_radius: circle_radius } end
task_16(circumference)
click to toggle source
# File lib/math_tasks.rb, line 125 def task_16(circumference) { area: (circumference**2 / (Math::PI * 4)).round(2) } end
task_17(outer_radius)
click to toggle source
# File lib/math_tasks.rb, line 129 def task_17(outer_radius) { area: (Math::PI * (outer_radius**2) - Math::PI * (20**2)).round(2) } end
task_183(p, arr)
click to toggle source
# File lib/math_tasks.rb, line 394 def task_183(p, arr) rez = arr.select { |a| (a.to_i % p.to_i).zero? && (a.to_i != 0) }.inject(1) { |r, a| r * a.to_i } { result: rez } end
task_19(v1, v2, a1, a2, s)
click to toggle source
# File lib/math_tasks.rb, line 133 def task_19(v1, v2, a1, a2, s) { time: ((- (v1 + v2) + Math.sqrt((v1 + v2) * (v1 + v2) + 2 * (a1 + a2) * s)) / (a1 + a2)).round(2) } end
task_2(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 70 def task_2(first_number, second_number) { result: (first_number.abs - second_number.abs) / (1 + first_number.abs * second_number.abs) } end
task_20(a, d, n)
click to toggle source
# File lib/math_tasks.rb, line 137 def task_20(a, d, n) sum = a (0...n).each do |i| sum += d * i end { sum: sum } end
task_22(base1, base2, angle)
click to toggle source
# File lib/math_tasks.rb, line 145 def task_22(base1, base2, angle) { square: (((base1 + base2) * ((base1 - base2).abs / 2) * Math.sin(angle * Math::PI / 180) / \ Math.cos(angle * Math::PI / 180)) / 2).round(2) } end
task_24(x1, x2, y1, y2)
click to toggle source
# File lib/math_tasks.rb, line 150 def task_24(x1, x2, y1, y2) { distance: Math.sqrt((x1 - x2)**2 + (y1 - y2)**2).round(2) } end
task_25(x1, y1, x2, y2, x3, y3)
click to toggle source
# File lib/math_tasks.rb, line 154 def task_25(x1, y1, x2, y2, x3, y3) a = Math.sqrt(Math.sqrt((x2 - x1).abs) + Math.sqrt((y2 - y1).abs)) b = Math.sqrt(Math.sqrt((x3 - x2).abs) + Math.sqrt((y3 - y2).abs)) c = Math.sqrt(Math.sqrt((x1 - x3).abs) + Math.sqrt((y1 - y3).abs)) p = ((a + b + c) / 2).round 2 s = Math.sqrt(p * (p - a) * (p - b) * (p - c)).round 2 { perimeter: p, square: s } end
task_251(str)
click to toggle source
# File lib/math_tasks.rb, line 399 def task_251(str) { result: str.count('x') } end
task_252(str)
click to toggle source
# File lib/math_tasks.rb, line 403 def task_252(str) { counter_plus: str.count('+'), counter_multiple: str.count('*'), counter_all: str.count('+') + str.count('-') + str.count('*') } end
task_26(radius, angle_radian)
click to toggle source
# File lib/math_tasks.rb, line 164 def task_26(radius, angle_radian) { square: (radius * radius * angle_radian / 2).round(2) } end
task_261(str)
click to toggle source
# File lib/math_tasks.rb, line 409 def task_261(str) arr = str.split('') space = 0 s = 0 rez = 0 e = 0 arr.each do |a| if a == ' ' s += 1 else space = s if s > space s = 0 end if a == 'e' e += 1 else rez = e if e > rez e = 0 end end { number_spaces: space, question: rez >= 5 } end
task_27(a, b, c)
click to toggle source
# File lib/math_tasks.rb, line 168 def task_27(a, b, c) s = a.to_f + b.to_f + c.to_f x = (a / s * 180).round 2 y = (b / s * 180).round 2 z = (c / s * 180).round 2 { angle_1: x, angle_2: y, angle_3: z } end
task_28(number)
click to toggle source
# File lib/math_tasks.rb, line 178 def task_28(number) { result: 6 + number * (-5 + number * (4 + number * (-3 + 2 * number))) } end
task_3(cube_side)
click to toggle source
# File lib/math_tasks.rb, line 74 def task_3(cube_side) { volume: cube_side**3, surface_area: cube_side**2 } end
task_33(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 182 def task_33(first_number, second_number) { max: first_number > second_number ? first_number : second_number, min: first_number > second_number ? second_number : first_number } end
task_36(x, y, z)
click to toggle source
# File lib/math_tasks.rb, line 187 def task_36(x, y, z) { result: x < y && y < z ? true : false } end
task_37(x, y, z)
click to toggle source
# File lib/math_tasks.rb, line 191 def task_37(x, y, z) if x >= y && y >= z x *= 2 y *= 2 z *= 2 else x = x.abs y = y.abs z = z.abs end { x: x, y: y, z: z } end
task_38(x, y)
click to toggle source
# File lib/math_tasks.rb, line 206 def task_38(x, y) { z: x > y ? x - y : y - x + 1 } end
task_39(x, y)
click to toggle source
# File lib/math_tasks.rb, line 210 def task_39(x, y) { result: x > y ? x : [x, y] } end
task_4(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 79 def task_4(first_number, second_number) { average: (first_number * second_number) / 2, geometric_mean: Math.sqrt((first_number * second_number)).round(2) } end
task_40(x, y)
click to toggle source
# File lib/math_tasks.rb, line 214 def task_40(x, y) x = 0 if x <= y { x: x, y: y } end
task_41(x, y, z)
click to toggle source
# File lib/math_tasks.rb, line 219 def task_41(x, y, z) arr = [] arr << x if x >= 1 && x <= 3 arr << y if y >= 1 && y <= 3 arr << z if z >= 1 && z <= 3 { result: arr } end
task_42(x, y)
click to toggle source
# File lib/math_tasks.rb, line 227 def task_42(x, y) if x > y y = (x + y) / 2 x = (x + y) * 2 else x = (x + y) / 2 y = (x + y) * 2 end { x: x, y: y } end
task_43(x, y, z)
click to toggle source
# File lib/math_tasks.rb, line 238 def task_43(x, y, z) x **= 2 if x >= 0 y **= 2 if y >= 0 z **= 2 if z >= 0 { x: x, y: y, z: z } end
task_45(a, b, c, d)
click to toggle source
# File lib/math_tasks.rb, line 245 def task_45(a, b, c, d) arr = [] arr << a << b << c << d m = arr.max rez = a > b && b > c && c > d if a <= b && b <= c && c <= d a = m b = m c = m d = m elsif !rez a **= 2 b **= 2 c **= 2 d **= 2 end { a: a, b: b, c: c, d: d } end
task_47(a, b, c)
click to toggle source
# File lib/math_tasks.rb, line 264 def task_47(a, b, c) if a < (b + c) && b < (a + c) && c < (a + b) if a == b || b == c || a == c if a == b && b == c && a == c { result: 'equilateral triangle' } else { result: 'isosceles triangle' } end else { result: 'arbitrary triangle' } end else { result: 'no triangle' } end end
task_5(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 84 def task_5(first_number, second_number) { average: (first_number * second_number) / 2, geometric_mean_mod: Math.sqrt((first_number.abs * second_number.abs)).round(2) } end
task_6(side1, side2)
click to toggle source
# File lib/math_tasks.rb, line 89 def task_6(side1, side2) { hypotenuse: Math.sqrt(side1**2 + side2**2).round(2), square: side1 * side2 / 2 } end
task_62(number)
click to toggle source
# File lib/math_tasks.rb, line 280 def task_62(number) { result: number.even? ? 'even' : 'odd' } end
task_63(a, b, r, _s)
click to toggle source
# File lib/math_tasks.rb, line 284 def task_63(a, b, r, _s) { result: (a % b == r) || (a % b == r) ? true : false } end
task_64(x)
click to toggle source
# File lib/math_tasks.rb, line 288 def task_64(x) { result: (x / 100).to_i } end
task_65(n)
click to toggle source
# File lib/math_tasks.rb, line 292 def task_65(n) { result: n**2 == n.to_s.split('').inject(0) { |sum, x| sum + x.to_i } } end
task_66(k, m, x, y, z)
click to toggle source
# File lib/math_tasks.rb, line 296 def task_66(k, m, x, y, z) if k < m**2 x = x.abs y -= 0.5 z -= 0.5 elsif k == m**2 y = y.abs x -= 0.5 z -= 0.5 else z = z.abs x -= 0.5 y -= 0.5 end { x: x, y: y, z: z } end
task_73(first_number, second_number)
click to toggle source
# File lib/math_tasks.rb, line 313 def task_73(first_number, second_number) p ' task 73:' arr = [] arr << first_number << second_number if first_number != second_number first_number = arr.max second_number = arr.max else first_number = 0 second_number = 0 end { first_number: first_number, second_number: second_number } end
task_74(age)
click to toggle source
# File lib/math_tasks.rb, line 327 def task_74(age) if age >= 11 && age <= 14 word = 'лет' else case age % 10 when 1 word = 'год' when 2, 3, 4 word = 'года' else word = 'лет' end end { result: age.to_s + ' ' + word } end
task_8(number_angle, radius)
click to toggle source
# File lib/math_tasks.rb, line 94 def task_8(number_angle, radius) { perimeter: (2 * number_angle * radius * Math.tan(Math::PI / number_angle)).round(2) } end
task_87(number1, number2)
click to toggle source
# File lib/math_tasks.rb, line 343 def task_87(number1, number2) sum = 0 i = 0 while number1 > 0 && i < number2 sum += number1 % 10 number1 /= 10 i += 1 end { sum: sum } end
task_9(resistor1, resistor2, resistor3)
click to toggle source
# File lib/math_tasks.rb, line 98 def task_9(resistor1, resistor2, resistor3) { total_resistance: (1 / (1 / resistor1.to_f + 1 / resistor2.to_f + 1 / resistor3.to_f)).round(2) } end
task_90(m, n)
click to toggle source
# File lib/math_tasks.rb, line 354 def task_90(m, n) nod = m.gcd(n) { p: m / nod, q: n / nod } end