Class: GeekHubTasks
- Inherits:
-
Object
- Object
- GeekHubTasks
- Defined in:
- lib/geekhub_tasks.rb
Class Method Summary collapse
- .a_or_both(a, b) ⇒ Object
- .age(n) ⇒ Object
- .area_circle(l) ⇒ Object
- .arithmetic_progression(a, d, n) ⇒ Object
- .average(a, b) ⇒ Object
- .average2(a, b) ⇒ Object
- .check(a, b, r, z) ⇒ Object
- .children(n) ⇒ Object
- .chs(k, l) ⇒ Object
- .cube(a) ⇒ Object
- .dano(a, b) ⇒ Object
- .defs(a, b) ⇒ Object
- .distance_between_two_points(x_1, x_2, y_1, y_2) ⇒ Object
- .does_it_exist(x, y, z) ⇒ Object
- .equality(a, b, c) ⇒ Object
- .even_number(n) ⇒ Object
- .fact(m, n) ⇒ Object
- .factor(n) ⇒ Object
- .fou_one(a, b, c) ⇒ Object
- .fourty(a, b) ⇒ Object
- .gsub(n) ⇒ Object
- .gsub_include(n) ⇒ Object
- .half_or_double(x, y) ⇒ Object
- .include_scan(n) ⇒ Object
- .math1(x, y) ⇒ Object
- .mix(v_1, t_1, v_2, t_2) ⇒ Object
- .mosn(x, y) ⇒ Object
- .new(v1, v2, a1, a2, s) ⇒ Object
- .number_of_hundreds(n) ⇒ Object
- .period(l) ⇒ Object
- .positive_power_two(a, b, c) ⇒ Object
- .power(n) ⇒ Object
- .powers(m1, m2, r) ⇒ Object
- .put(a) ⇒ Object
- .quadratic_equation(a, b, c) ⇒ Object
- .rad(r1, r2) ⇒ Object
- .real(a, b, c, d) ⇒ Object
- .sides_triangle(a_1, b_1, r) ⇒ Object
- .sixty_eight_a(n) ⇒ Object
- .sixty_five(n) ⇒ Object
- .sixty_seven(n) ⇒ Object
- .string(n) ⇒ Object
- .temp(b) ⇒ Object
- .test(n) ⇒ Object
- .time(h) ⇒ Object
- .trapezium(a, b, c) ⇒ Object
- .triangle(a, b) ⇒ Object
- .triangle_area(a) ⇒ Object
- .two_tasks(x) ⇒ Object
- .x_or_y(x, y) ⇒ Object
Class Method Details
.a_or_both(a, b) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/geekhub_tasks.rb', line 90 def self.a_or_both(a, b) if a > b p = "First item" else p = "Both items" end { :p => p } end |
.age(n) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/geekhub_tasks.rb', line 158 def self.age(n) if n % 10 == 1 && n != 11 p = " Год " elsif n >= 5 && n <= 20 p = " Лет " elsif n % 10 <= 4 && n % 10 > 0 p = " Годa " else p = " Лет " end {:p => p } end |
.area_circle(l) ⇒ Object
25 26 27 28 |
# File 'lib/geekhub_tasks.rb', line 25 def self.area_circle(l) s = ( (l ** 2) / 4 * Math::PI ).round(2) { s: s } end |
.arithmetic_progression(a, d, n) ⇒ Object
38 39 40 41 |
# File 'lib/geekhub_tasks.rb', line 38 def self.arithmetic_progression(a, d, n) s = ( 2 * a + ( n - 1 ) * d ) * n/2 { s: s } end |
.average(a, b) ⇒ Object
9 10 11 12 13 |
# File 'lib/geekhub_tasks.rb', line 9 def self.average(a, b) average_ariphmetic = ( a + b )/2 average_geometric = Math.sqrt( a * b ).round(1) { average_ariphmetic: average_ariphmetic, average_geometric: average_geometric } end |
.average2(a, b) ⇒ Object
400 401 402 403 404 |
# File 'lib/geekhub_tasks.rb', line 400 def self.average2(a, b) average_ariphmetic = ( a.abs + b.abs ) / 2 average_geometric = Math.sqrt( a.abs * b.abs ).round(1) { average_ariphmetic: average_ariphmetic, average_geometric: average_geometric } end |
.check(a, b, r, z) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/geekhub_tasks.rb', line 108 def self.check(a, b, r, z) ab = a % b if ab == r || ab == z s = "Really,the remainder is set to the given numbers" else s = "No,the remainder is no set to the given numbers" end { :s => s } end |
.children(n) ⇒ Object
395 396 397 398 |
# File 'lib/geekhub_tasks.rb', line 395 def self.children(n) z = n.gsub!(/child/, "children") { :p => "#{z}" } end |
.chs(k, l) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/geekhub_tasks.rb', line 181 def self.chs(k, l) if k != l sol = "k != l" #k = ( k + l) && l = ( k + l ) else sol = "k && l = 0" #k = 0 && l = 0 end { :sol => sol } end |
.cube(a) ⇒ Object
261 262 263 264 265 |
# File 'lib/geekhub_tasks.rb', line 261 def self.cube(a) v = ( a**3 ) s = ( 6 * ( a**2 ) ) { v: v, s:s } end |
.dano(a, b) ⇒ Object
248 249 250 251 252 253 |
# File 'lib/geekhub_tasks.rb', line 248 def self.dano(a, b) c = ( Math.sqrt( ( b**2 ) - ( a ** 2 ) ) ).round(0) r = ( ( a + c - b)/2 ).round(0) { c: c, r: r } end |
.defs(a, b) ⇒ Object
440 441 442 443 444 445 446 447 448 |
# File 'lib/geekhub_tasks.rb', line 440 def self.defs(a, b) x = a.to_i.gcdlcm b.to_i if a.to_i == 0 || b.to_i == 0 p = "Danger!You try division on 0" else p = "Greatest common divisor" end { :p => p } end |
.distance_between_two_points(x_1, x_2, y_1, y_2) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/geekhub_tasks.rb', line 43 def self.distance_between_two_points(x_1, x_2, y_1, y_2) point_1 = (x_2 - x_1) point_2 = (y_2 - y_1) s = Math.sqrt(point_1.to_i**2 + point_2.to_i**2).round(2) { s: s } end |
.does_it_exist(x, y, z) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/geekhub_tasks.rb', line 406 def self.does_it_exist(x, y, z) if x + y >= z || x + z >= y || y + z >= x s1 = "Triangle exist" else s2 = "This is not triangle" end if x < y k = x; m = y; else k = y; m = x; end if m < z h = z else h = m; m = z; end t1 = h * h t2 = k * k + m * m if t1 < t2 t1 = "This is an angular triangle" else t2 = "This isn't an angular triangle" end { rez1: s1, rez2: t2 } end |
.equality(a, b, c) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/geekhub_tasks.rb', line 72 def self.equality(a, b, c) if a < b && b < c p = "Equality is fulfilled" else p = "We have trouble with equality" end { :p => p } end |
.even_number(n) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/geekhub_tasks.rb', line 99 def self.even_number(n) if n % 2 == 0 p = "Number is even" else p = "Sorry,number isn't even" end { :p => p} end |
.fact(m, n) ⇒ Object
339 340 341 342 343 344 |
# File 'lib/geekhub_tasks.rb', line 339 def self.fact(m, n) n_1 = Math.gamma(n+1) m_1 = Math.gamma(m+1) m_n = Math.gamma( ( m + n ) + 1 ) { result: ( n_1 + m_1 )/m_n } end |
.factor(n) ⇒ Object
176 177 178 179 |
# File 'lib/geekhub_tasks.rb', line 176 def self.factor(n) x = Math.gamma(n+1) { f: x } end |
.fou_one(a, b, c) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/geekhub_tasks.rb', line 215 def self.fou_one(a, b, c) if a >= 1 && a <= 3 a = "belong to the gap" else a = "do not belong to the gap" end if b >= 1 && b <= 3 b = "belong to the gap" else b = "do not belong to the gap" end if c >= 1 && c <= 3 c = "belong to the gap" else c = "do not belong to the gap" end { a: a, b:b, c:c} end |
.fourty(a, b) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/geekhub_tasks.rb', line 148 def self.fourty(a, b) if a <= b p = ("a = 0") a = 0 else p = "a > b" end { :p => p } end |
.gsub(n) ⇒ Object
285 286 287 288 289 290 291 292 293 294 |
# File 'lib/geekhub_tasks.rb', line 285 def self.gsub(n) n.downcase! if n.to_s.gsub!(/!/, ".") s = "Your redacted string is #{n}" else puts "Nothing to do here!" end puts "Your string is: #{n}" { :s => s } end |
.gsub_include(n) ⇒ Object
312 313 314 315 316 317 318 319 |
# File 'lib/geekhub_tasks.rb', line 312 def self.gsub_include(n) if n.to_s.include? "*" x = n.gsub(/!/, "-") end puts "Text before redacted: #{n}" z = "Text after redacted: #{x}" { :z => z } end |
.half_or_double(x, y) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/geekhub_tasks.rb', line 236 def self.half_or_double(x, y) if x < y x = ( x + y ) / 2 y = ( x + y ) * 2 else y = ( x + y ) / 2 x = ( x + y ) * 2 end { sol1: x, sol2: y } end |
.include_scan(n) ⇒ Object
303 304 305 306 307 308 309 310 |
# File 'lib/geekhub_tasks.rb', line 303 def self.include_scan(n) if n.include? "eeeee" s = "Yes, string include 'eeeee' " else s = "No, string includen't 'eeeee' " end { :s => s } end |
.math1(x, y) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/geekhub_tasks.rb', line 203 def self.math1(x, y) sum = x + y diff = x - y comp = x * y { sum: sum, diff: diff, comp: comp} end |
.mix(v_1, t_1, v_2, t_2) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/geekhub_tasks.rb', line 50 def self.mix(v_1, t_1, v_2, t_2) z = v_1 + v_2 t = ( ( v_1 * t_1 ) + ( v_2 * t_2 ) )/z.to_i { v: z, t: t } end |
.mosn(x, y) ⇒ Object
359 360 361 362 363 364 |
# File 'lib/geekhub_tasks.rb', line 359 def self.mosn(x, y) max = [x, y].max min = [x, y].min minmax = [x, y].minmax {max: max, min: min, minmax: minmax} end |
.new(v1, v2, a1, a2, s) ⇒ Object
381 382 383 384 |
# File 'lib/geekhub_tasks.rb', line 381 def self.new(v1, v2, a1, a2, s) result = ( (-(v1+v2)+Math.sqrt( ( (v1+v2) ** 2 )+ 2 * ( a1 + a2 ) * s ) )/( a1 + a2 ) ).round(0) { result: result } end |
.number_of_hundreds(n) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/geekhub_tasks.rb', line 118 def self.number_of_hundreds(n) num = n / 100 if n > 99 s = 1 else s = 2 end {s: s} end |
.period(l) ⇒ Object
20 21 22 23 |
# File 'lib/geekhub_tasks.rb', line 20 def self.period(l) t = ( 2 * Math::PI * (l / 9.8 ) ).round(2) { t: t } end |
.positive_power_two(a, b, c) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/geekhub_tasks.rb', line 346 def self.positive_power_two(a, b, c) if a > 0 a = a ** 2 end if b > 0 b = b ** 2 end if c > 0 c = c ** 2 end { c: c } end |
.power(n) ⇒ Object
171 172 173 174 |
# File 'lib/geekhub_tasks.rb', line 171 def self.power(n) x = n**2 { x: x } end |
.powers(m1, m2, r) ⇒ Object
210 211 212 213 |
# File 'lib/geekhub_tasks.rb', line 210 def self.powers(m1, m2, r) x = (m1 * m2)/(r**2) { sol: x } end |
.put(a) ⇒ Object
333 334 335 336 337 |
# File 'lib/geekhub_tasks.rb', line 333 def self.put(a) arr = [] x = ( 1..a ).select{ |x| arr << x if a % x == 0 } { res: arr} end |
.quadratic_equation(a, b, c) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/geekhub_tasks.rb', line 267 def self.quadratic_equation(a, b, c) d = b * b - 4 * a * c if (d == 0) x1 = ( -b/2/a ) && x2 = ( -b/2/a ) else end if (d > 0) x1 = ( (-b-Math.sqrt(d))/2/a).round(2) x2 = ( (-b+Math.sqrt(d))/2/a).round(2) else x1 = (-b/2/a) +(Math.sqrt(-d)/2/a).round(2) x2 = (-b/2/a) +(-Math.sqrt(-d)/2/a).round(2) end { x1: x1, x2: x2 } end |
.rad(r1, r2) ⇒ Object
372 373 374 375 376 377 378 379 |
# File 'lib/geekhub_tasks.rb', line 372 def self.rad(r1, r2) if r1 < r2 r = ( Math::PI * ( r1 ** 2) - ( r2 ** 2) ).round(2) else r = "das" end { r: r } end |
.real(a, b, c, d) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/geekhub_tasks.rb', line 321 def self.real(a, b, c, d) z = [a ** 2, b ** 2, c ** 2, d ** 2 ] if a <= b && b <= c && c <= d norm = "Highest number " elsif a > b && b > c && c > d norm = "Digital in normal" else norm = "Squares of numbers #{z}" end { :norm => norm } end |
.sides_triangle(a_1, b_1, r) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/geekhub_tasks.rb', line 30 def self.sides_triangle(a_1, b_1, r) c_1 = ( 180 - ( a_1 + b_1 ) ) a = 2 * r * Math.sin(a_1 * ( Math::PI/180 ) ).round(2) b = 2 * r * Math.sin(b_1 * ( Math::PI/180 ) ).round(2) c = 2 * r * Math.sin(c_1.to_i * ( Math::PI/180 ) ).round(2) { a: a, b: b, c:c } end |
.sixty_eight_a(n) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/geekhub_tasks.rb', line 139 def self.sixty_eight_a(n) if n.to_s.reverse == n.to_s p = "This number is palindrome" else p = "This number is'nt palindrome" end { :p => p } end |
.sixty_five(n) ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/geekhub_tasks.rb', line 192 def self.sixty_five(n) a = n/10 b = n - a.to_i * 10 if a**2 == ( a + b )**3 z = "Yes, n**2 = n(digital**3)" else z = "No, n**2 != n(digital**3)" end { :z => z } end |
.sixty_seven(n) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/geekhub_tasks.rb', line 128 def self.sixty_seven(n) x = n.to_s.length # number of digits in number z = n.to_s.chars.map { |sum,n| sum = sum.to_i + n.to_i} # display sum x = n.to_s.split('') y = x.to_a f = "Display the first digit " + y[0].to_s # display first digit s = "Display the last digit " + y[-1].to_s # display the last digit t = "Display the penultimate digit " + y[-2].to_s # dispaly penultimate digit { :f => f, :s => s, :t => t} end |
.string(n) ⇒ Object
296 297 298 299 300 301 |
# File 'lib/geekhub_tasks.rb', line 296 def self.string(n) puts "Your string before readected: " + "#{n}" n.delete! "*" str1 = "Your string after readected: #{n}" { :str1 => str1 } end |
.temp(b) ⇒ Object
366 367 368 369 370 |
# File 'lib/geekhub_tasks.rb', line 366 def self.temp(b) to_f = ( ( 0..b ).each { |t| return ( t * 1.8 + 32 ).round(2) } ) { to_f: to_f } end |
.test(n) ⇒ Object
386 387 388 389 390 391 392 393 |
# File 'lib/geekhub_tasks.rb', line 386 def self.test(n) if n.to_s.include?("3") p = "Yes,include" else p = "No" end { :p => p} end |
.time(h) ⇒ Object
15 16 17 18 |
# File 'lib/geekhub_tasks.rb', line 15 def self.time(h) t = Math.sqrt( 2 * ( h/9.8) ) { t: t } end |
.trapezium(a, b, c) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/geekhub_tasks.rb', line 62 def self.trapezium(a, b, c) if a < b puts "Mistake..b can't be greater than a" end x = ( ( ( a - b )/2 ) * Math.tan(c) ).round(2) s = ( ( a + b ) * x.to_i)/2 { h: x, s: s } end |
.triangle(a, b) ⇒ Object
3 4 5 6 7 |
# File 'lib/geekhub_tasks.rb', line 3 def self.triangle(a, b) hypotenuse = Math.sqrt( ( a**2 ) + ( b**2 ) ).round(2) area = ( a * b )/2 { hypotenuse: hypotenuse, area: area } end |
.triangle_area(a) ⇒ Object
57 58 59 60 |
# File 'lib/geekhub_tasks.rb', line 57 def self.triangle_area(a) s = ( a**2 ) * (Math.sqrt(3)/4).round(2) { s: s } end |
.two_tasks(x) ⇒ Object
255 256 257 258 259 |
# File 'lib/geekhub_tasks.rb', line 255 def self.two_tasks(x) result_1 = ( 1 - 2 * x + ( 3 * (x**2 ) ) - ( 4 * ( x**3 ) ) ) result_2 = ( 1 + 2 * x + ( 3 * (x**2 ) ) + ( 4 * ( x**3 ) ) ) { result_1: result_1, result_2: result_2 } end |
.x_or_y(x, y) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/geekhub_tasks.rb', line 81 def self.x_or_y(x, y) if x > y z = x - y else z = y - x + 1 end { z: z } end |