Class: MathTasks
- Inherits:
-
Object
- Object
- MathTasks
- Defined in:
- lib/math_tasks.rb
Class Method Summary collapse
- .task3_73(first_number, second_number) ⇒ Object
- .task_1(first_number, second_number) ⇒ Object
- .task_10(height) ⇒ Object
- .task_107(m) ⇒ Object
- .task_108(number) ⇒ Object
- .task_109(number) ⇒ Object
- .task_12(side) ⇒ Object
- .task_13(length) ⇒ Object
- .task_14(mass1, mass2, distance) ⇒ Object
- .task_15(first_leg, hypotenuse) ⇒ Object
- .task_16(circumference) ⇒ Object
- .task_17(outer_radius) ⇒ Object
- .task_183(p, arr) ⇒ Object
- .task_19(v1, v2, a1, a2, s) ⇒ Object
- .task_2(first_number, second_number) ⇒ Object
- .task_20(a, d, n) ⇒ Object
- .task_22(base1, base2, angle) ⇒ Object
- .task_24(x1, x2, y1, y2) ⇒ Object
- .task_25(x1, y1, x2, y2, x3, y3) ⇒ Object
- .task_251(str) ⇒ Object
- .task_252(str) ⇒ Object
- .task_26(radius, angle_radian) ⇒ Object
- .task_261(str) ⇒ Object
- .task_27(a, b, c) ⇒ Object
- .task_28(number) ⇒ Object
- .task_3(cube_side) ⇒ Object
- .task_33(first_number, second_number) ⇒ Object
- .task_36(x, y, z) ⇒ Object
- .task_37(x, y, z) ⇒ Object
- .task_38(x, y) ⇒ Object
- .task_39(x, y) ⇒ Object
- .task_4(first_number, second_number) ⇒ Object
- .task_40(x, y) ⇒ Object
- .task_41(x, y, z) ⇒ Object
- .task_42(x, y) ⇒ Object
- .task_43(x, y, z) ⇒ Object
- .task_45(a, b, c, d) ⇒ Object
- .task_47(a, b, c) ⇒ Object
- .task_5(first_number, second_number) ⇒ Object
- .task_6(side1, side2) ⇒ Object
- .task_62(number) ⇒ Object
- .task_63(a, b, r, _s) ⇒ Object
- .task_64(x) ⇒ Object
- .task_65(n) ⇒ Object
- .task_66(k, m, x, y, z) ⇒ Object
- .task_74(age) ⇒ Object
- .task_8(number_angle, radius) ⇒ Object
- .task_87(number1, number2) ⇒ Object
- .task_9(resistor1, resistor2, resistor3) ⇒ Object
- .task_90(m, n) ⇒ Object
Class Method Details
.task3_73(first_number, second_number) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/math_tasks.rb', line 251 def self.task3_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_1(first_number, second_number) ⇒ Object
2 3 4 5 6 |
# File 'lib/math_tasks.rb', line 2 def self.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) ⇒ Object
40 41 42 |
# File 'lib/math_tasks.rb', line 40 def self.task_10(height) { time_fall: Math.sqrt(2 * height / 9.8).round(2) } end |
.task_107(m) ⇒ Object
298 299 300 301 302 303 304 305 306 |
# File 'lib/math_tasks.rb', line 298 def self.task_107(m) rez = 0 i = 0 while rez < m i += 1 rez = 4**i end { k: i - 1 } end |
.task_108(number) ⇒ Object
308 309 310 311 312 313 314 315 316 |
# File 'lib/math_tasks.rb', line 308 def self.task_108(number) rez = 0 i = 0 while rez < number i += 1 rez = 2**i end { result: rez } end |
.task_109(number) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/math_tasks.rb', line 318 def self.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) ⇒ Object
44 45 46 |
# File 'lib/math_tasks.rb', line 44 def self.task_12(side) { square: (side**2 * Math.sqrt(3) / 4).round(2) } end |
.task_13(length) ⇒ Object
48 49 50 |
# File 'lib/math_tasks.rb', line 48 def self.task_13(length) { oscillation_period: (2**Math::PI * Math.sqrt(length) / 9.8).round(2) } end |
.task_14(mass1, mass2, distance) ⇒ Object
52 53 54 |
# File 'lib/math_tasks.rb', line 52 def self.task_14(mass1, mass2, distance) { force_attraction: mass1 * mass2 * 6.67e-11 / distance**2 } end |
.task_15(first_leg, hypotenuse) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/math_tasks.rb', line 56 def self.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) ⇒ Object
63 64 65 |
# File 'lib/math_tasks.rb', line 63 def self.task_16(circumference) { area: (circumference**2 / (Math::PI * 4)).round(2) } end |
.task_17(outer_radius) ⇒ Object
67 68 69 |
# File 'lib/math_tasks.rb', line 67 def self.task_17(outer_radius) { area: (Math::PI * (outer_radius**2) - Math::PI * (20**2)).round(2) } end |
.task_183(p, arr) ⇒ Object
332 333 334 335 |
# File 'lib/math_tasks.rb', line 332 def self.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) ⇒ Object
71 72 73 |
# File 'lib/math_tasks.rb', line 71 def self.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) ⇒ Object
8 9 10 |
# File 'lib/math_tasks.rb', line 8 def self.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) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/math_tasks.rb', line 75 def self.task_20(a, d, n) sum = a (0...n).each do |i| sum += d * i end { sum: sum } end |
.task_22(base1, base2, angle) ⇒ Object
83 84 85 86 |
# File 'lib/math_tasks.rb', line 83 def self.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) ⇒ Object
88 89 90 |
# File 'lib/math_tasks.rb', line 88 def self.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) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/math_tasks.rb', line 92 def self.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) ⇒ Object
337 338 339 |
# File 'lib/math_tasks.rb', line 337 def self.task_251(str) { result: str.count('x') } end |
.task_252(str) ⇒ Object
341 342 343 344 345 |
# File 'lib/math_tasks.rb', line 341 def self.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) ⇒ Object
102 103 104 |
# File 'lib/math_tasks.rb', line 102 def self.task_26(radius, angle_radian) { square: (radius * radius * angle_radian / 2).round(2) } end |
.task_261(str) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/math_tasks.rb', line 347 def self.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) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/math_tasks.rb', line 106 def self.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) ⇒ Object
116 117 118 |
# File 'lib/math_tasks.rb', line 116 def self.task_28(number) { result: 6 + number * (-5 + number * (4 + number * (-3 + 2 * number))) } end |
.task_3(cube_side) ⇒ Object
12 13 14 15 |
# File 'lib/math_tasks.rb', line 12 def self.task_3(cube_side) { volume: cube_side**3, surface_area: cube_side**2 } end |
.task_33(first_number, second_number) ⇒ Object
120 121 122 123 |
# File 'lib/math_tasks.rb', line 120 def self.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) ⇒ Object
125 126 127 |
# File 'lib/math_tasks.rb', line 125 def self.task_36(x, y, z) { result: x < y && y < z ? true : false } end |
.task_37(x, y, z) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/math_tasks.rb', line 129 def self.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) ⇒ Object
144 145 146 |
# File 'lib/math_tasks.rb', line 144 def self.task_38(x, y) { z: x > y ? x - y : y - x + 1 } end |
.task_39(x, y) ⇒ Object
148 149 150 |
# File 'lib/math_tasks.rb', line 148 def self.task_39(x, y) { result: x > y ? x : [x, y] } end |
.task_4(first_number, second_number) ⇒ Object
17 18 19 20 |
# File 'lib/math_tasks.rb', line 17 def self.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) ⇒ Object
152 153 154 155 |
# File 'lib/math_tasks.rb', line 152 def self.task_40(x, y) x = 0 if x <= y { x: x, y: y } end |
.task_41(x, y, z) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/math_tasks.rb', line 157 def self.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) ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/math_tasks.rb', line 165 def self.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) ⇒ Object
176 177 178 179 180 181 |
# File 'lib/math_tasks.rb', line 176 def self.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) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/math_tasks.rb', line 183 def self.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) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/math_tasks.rb', line 202 def self.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) ⇒ Object
22 23 24 25 |
# File 'lib/math_tasks.rb', line 22 def self.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) ⇒ Object
27 28 29 30 |
# File 'lib/math_tasks.rb', line 27 def self.task_6(side1, side2) { hypotenuse: Math.sqrt(side1**2 + side2**2).round(2), square: side1 * side2 / 2 } end |
.task_62(number) ⇒ Object
218 219 220 |
# File 'lib/math_tasks.rb', line 218 def self.task_62(number) { result: number.even? ? 'even' : 'odd' } end |
.task_63(a, b, r, _s) ⇒ Object
222 223 224 |
# File 'lib/math_tasks.rb', line 222 def self.task_63(a, b, r, _s) { result: (a % b == r) || (a % b == r) ? true : false } end |
.task_64(x) ⇒ Object
226 227 228 |
# File 'lib/math_tasks.rb', line 226 def self.task_64(x) { result: (x / 100).to_i } end |
.task_65(n) ⇒ Object
230 231 232 |
# File 'lib/math_tasks.rb', line 230 def self.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) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/math_tasks.rb', line 234 def self.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_74(age) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/math_tasks.rb', line 265 def self.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) ⇒ Object
32 33 34 |
# File 'lib/math_tasks.rb', line 32 def self.task_8(number_angle, radius) { perimeter: (2 * number_angle * radius * Math.tan(Math::PI / number_angle)).round(2) } end |
.task_87(number1, number2) ⇒ Object
281 282 283 284 285 286 287 288 289 290 |
# File 'lib/math_tasks.rb', line 281 def self.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) ⇒ Object
36 37 38 |
# File 'lib/math_tasks.rb', line 36 def self.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) ⇒ Object
292 293 294 295 296 |
# File 'lib/math_tasks.rb', line 292 def self.task_90(m, n) nod = m.gcd(n) { p: m / nod, q: n / nod } end |