Class: Mathsuite

Inherits:
Object
  • Object
show all
Defined in:
lib/mathsuite.rb

Class Method Summary collapse

Class Method Details

.dz1(a, b) ⇒ Object



5
6
7
# File 'lib/mathsuite.rb', line 5

def dz1(a, b)
  { summa: a+b, diff: a-b, multiply: a*b }
end

.dz10(h) ⇒ Object



41
42
43
# File 'lib/mathsuite.rb', line 41

def dz10(h)
  { falling_time: Math.sqrt(2*h/9.8) }
end

.dz11(x, y, z) ⇒ Object



45
46
47
# File 'lib/mathsuite.rb', line 45

def dz11(x, y, z)
  { a: (Math.sqrt((x-1).abs)-(y.abs)**1.0/3.0)/(1+x**2/2+y**2/4) , b: x*(Math.atan(z)+Math.exp(-x-3))}
end

.dz12(a) ⇒ Object



49
50
51
# File 'lib/mathsuite.rb', line 49

def dz12(a)
  { triangel_square: a**2*Math.sqrt(3)/4}
end

.dz13(l) ⇒ Object



53
54
55
# File 'lib/mathsuite.rb', line 53

def dz13(l)
  { Period_mayatnika: 2*Math::PI * Math.sqrt(l)/9.8}
end

.dz14(m1, m2, r) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/mathsuite.rb', line 57

def dz14(m1, m2, r)
  g = 6.7385/10**11
  if r.nonzero?
    f = g.to_f*m1*m2/r**2
  else
    f = 0
  end
end

.dz15(a, b) ⇒ Object



66
67
68
69
70
71
# File 'lib/mathsuite.rb', line 66

def dz15(a, b)
  c = Math.sqrt(a**2-b**2)
  p = (a+b+c)/2
  r = Math.sqrt((p-a)*(p-b)*(p-c)/p)
  { katet2: c, radius: r}
end

.dz16(p) ⇒ Object



73
74
75
# File 'lib/mathsuite.rb', line 73

def dz16(p)
  { square: p**2/(8*Math::PI)}
end

.dz17(r1, r2) ⇒ Object



77
78
79
# File 'lib/mathsuite.rb', line 77

def dz17(r1,r2)
  { circle_square: Math::PI*(r2**2-r1**2)/2}
end

.dz18(a, b, c) ⇒ Object



81
82
83
84
85
86
# File 'lib/mathsuite.rb', line 81

def dz18(a, b, c)
  a = 2*r* Math.sin(alpha*Math::PI/180)
  b = 2*r* Math.sin(beta*Math::PI/180)
  c = 2*r* Math.sin(gama*Math::PI/180)
  {a: a,b: b,c: c}
end

.dz19(v1, v2, a1, a2, s) ⇒ Object



88
89
90
91
# File 'lib/mathsuite.rb', line 88

def dz19(v1, v2, a1, a2, s)
  t = ((-2*(v1+v2))+Math.sqrt(4*((v1+v2)**2)+8*(a1+a2)*s))/2*(a1+a2);
  { t: t}
end

.dz196Object



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/mathsuite.rb', line 186

def dz196()
  ar = []
  x =10
  1.upto(50) do
    ar.push(x)
    x+=1
  end
  { arB: ar.each.map { |x| if x.odd?
                             x=x*2
                           else
                             x = x
                           end } }
end

.dz2(x, y) ⇒ Object



9
10
11
# File 'lib/mathsuite.rb', line 9

def dz2(x, y)
  { value: (x.abs -y.abs)/(1+(x*y).abs) }
end

.dz20(a, d, n) ⇒ Object



93
94
95
# File 'lib/mathsuite.rb', line 93

def dz20(a, d, n)
  { summa: (2*a + d*(n-1))*n/2}
end

.dz200(a, n) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/mathsuite.rb', line 200

def dz200(a, n)
  if !((1..n).to_a.include?(a))
    return 0
  else
    i = 0
    (1..n).to_a.each do |x|
      if x==a
        return i
      end
      i+=1
    end
  end
  { res: "no #{a} in sequence"}
end

.dz204(n) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/mathsuite.rb', line 215

def dz204(n)
  score = []
  1.upto(n) {|x| score.push (x+2) }
  score.sort!.shift
  score.pop
  { score: score.inject{ |sum, el| sum + el }.to_f/score.size }
end

.dz205(str) ⇒ Object



223
224
225
# File 'lib/mathsuite.rb', line 223

def dz205(str)
  { res: str.chars.delete_if { |x| x=="0"||x=="5" }.join }
end

.dz224(n) ⇒ Object



227
228
229
# File 'lib/mathsuite.rb', line 227

def dz224(n)
  { res: (1..n).select { |x| x = x if (n % x).zero?} }
end

.dz225(n) ⇒ Object



231
232
233
# File 'lib/mathsuite.rb', line 231

def dz225(n)
  { res: (1..n).select { |x| (n % x**2).zero? && (n % x**3).nonzero?} }
end

.dz251(str) ⇒ Object



235
236
237
# File 'lib/mathsuite.rb', line 235

def dz251(str)
  { res:str.chars.count("x")}
end

.dz258(str, char1) ⇒ Object



239
240
241
# File 'lib/mathsuite.rb', line 239

def dz258(str, char1)
  { res: str.chars.delete(char1) }
end

.dz259(str, char1) ⇒ Object



243
244
245
246
# File 'lib/mathsuite.rb', line 243

def dz259(str, char1)
  ar = str.chars.delete_if{|x| x== char1 }
  { res: ar.map { |x| x = x + x if x!=char1 } }
end

.dz3(x) ⇒ Object



13
14
15
# File 'lib/mathsuite.rb', line 13

def dz3(x)
  { volume: x**3,surface_area: x**2}
end

.dz33(x, y) ⇒ Object



97
98
99
100
101
102
# File 'lib/mathsuite.rb', line 97

def dz33(x, y)
  a = [x,y]
  var_max = a.max()
  var_min = a.min()
  { max: var_max, min:var_min}
end

.dz330(n) ⇒ Object



248
249
250
251
252
253
254
255
256
257
# File 'lib/mathsuite.rb', line 248

def dz330(n)
  res = []
  1.upto(n) do |x|
    ar = (1..x).select { |y| (n % y).zero? ? y = y : y = 0}
    if x.equal?(ar.sum())
      res.push(x)
    end
  end
  { res_perfect_num: res}
end

.dz331(num) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/mathsuite.rb', line 259

def dz331(num)
  res  = []
  1.upto(num) do |x|
    1.upto(num) do |y|
      1.upto(num) do |z|
        summa = (x**2) + (y**2) + (z**2)
        res.push([x,y,z]) if summa.equal?(num)
      end
    end
  end
  { res_num: res}
end

.dz332(num) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/mathsuite.rb', line 272

def dz332(num)
  res  = []
  1.upto(num) do |x|
    1.upto(num) do |y|
      1.upto(num) do |z|
        1.upto(num) do |t|
          summa = (x**2) + (y**2) + (z**2)+(t**2)
          res.push([x,y,z,t]) if summa.equal?(num)
        end
      end
    end
  end
end

.dz34(x, y, z) ⇒ Object



104
105
106
107
108
109
# File 'lib/mathsuite.rb', line 104

def dz34(x, y, z)
  a = [x,y,z]
  var_max = a.max()
  var_min = a.min()
  [{ max: var_max}, {min:var_min, max1: var_max}]
end

.dz347(array) ⇒ Object



286
287
288
289
290
291
# File 'lib/mathsuite.rb', line 286

def dz347(array)
  mmin = array.min
  mmax = array.max
  enumer = mmin..mmax
  { numbers: enumer.reject { |x| array.include?(x) } }
end

.dz35(x, y, z) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/mathsuite.rb', line 111

def dz35(x, y, z)
  a = [x+y+z,x*y*z]
  b = [x+y+z/2.0,x*y*z]
  var_max = a.max()
  var_min = b.min()**2+1
  { max: var_max, min:var_min }
end

.dz36(a, b, c) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/mathsuite.rb', line 119

def dz36(a, b, c)
  if a<b &&b<c
    {a_Less_b_Less_c: true}
  else
    {a_Less_b_Less_c: false}
  end
end

.dz37(a, b, c) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/mathsuite.rb', line 127

def dz37(a, b, c)
  if c<=b &&b<=a
    [a,b,c].each {|x| x*2}
  else
    [a,b,c].each {|x| x.abs}
  end
end

.dz38(x, y) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/mathsuite.rb', line 135

def dz38(x,y)
  if x>y
    z = x-y
  else
    z = y-x+1
  end
  { z: z}
end

.dz39(x, y) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/mathsuite.rb', line 144

def dz39(x, y)
  if x>y
    z =x
  else
    z = [x,y]
  end
  { z: z}
end

.dz4(x, y) ⇒ Object



17
18
19
# File 'lib/mathsuite.rb', line 17

def dz4(x, y)
  { sr_arifmet: (x+y)/2, sr_geometr: Math.sqrt(x*y)}
end

.dz40(x, y) ⇒ Object



153
154
155
156
# File 'lib/mathsuite.rb', line 153

def dz40(x, y)
  x=0 if x <= y
  { result: [x, y] }
end

.dz41(x, y, z) ⇒ Object



158
159
160
# File 'lib/mathsuite.rb', line 158

def dz41(x, y, z)
  { res: [x,y,z].select {|a| (a>1) && (a<3) }}
end

.dz42(x, y) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/mathsuite.rb', line 162

def dz42(x, y)
  if x == y
    return "must be x!=y"
  elsif x<y
    x_tmp = x
    x = (x+y)/2.0
    y = 2*x_tmp*y
  else
    y_tmp = y
    y = (x+y)/2.0
    x = 2*y_tmp*x
  end
  { res: [x, y]}
end

.dz43(x, y, z) ⇒ Object



177
178
179
# File 'lib/mathsuite.rb', line 177

def dz43(x, y, z)
  { res: [x,y,z].each {|a| a = a**2 if a >= 0} }
end

.dz434(aarr, barr) ⇒ Object



293
294
295
296
297
# File 'lib/mathsuite.rb', line 293

def dz434(aarr, barr)
  ares = aarr.map.with_index { |x, i| i > aarr.index(aarr.max)? x = 0.5 : x }
  bres = barr.map.with_index { |x, i| i > barr.index(barr.max)? x = 0.5 : x}
  { ares: ares, bres: bres}
end

.dz435(aarr, barr, k) ⇒ Object



299
300
301
302
303
# File 'lib/mathsuite.rb', line 299

def dz435(aarr, barr, k)
  aarr[aarr.index(aarr.max)] = k unless aarr.include?(k)
  barr[barr.index(barr.max)] = k unless barr.include?(k)
  { aarr: aarr, barr: barr}
end

.dz462(char1) ⇒ Object



305
306
307
308
309
310
311
# File 'lib/mathsuite.rb', line 305

def dz462(char1)
  if (('a'..'z').include?(char1)) || (('A'..'Z').include?(char1))
    { is_a_letter?: true }
  else
    { is_a_letter?: false }
  end
end

.dz468(str1, str2) ⇒ Object



313
314
315
316
317
318
319
320
# File 'lib/mathsuite.rb', line 313

def dz468(str1, str2)
  flag = false
  str2.chars.each do |x|
    flag = str1.include?(x)
    return { sym: x, index: str1.chars.index(x)} if flag
  end
  -1 unless flag
end

.dz469(str1, width) ⇒ Object



322
323
324
325
# File 'lib/mathsuite.rb', line 322

def dz469(str1, width)
  delta = width - str1.size
  str1.chars.select { |char| char == " " ? (char << " ") : (char = char) }.join
end

.dz5(x, y) ⇒ Object



21
22
23
# File 'lib/mathsuite.rb', line 21

def dz5(x, y)
  { sr_arifmet: (x+y)/2, sr_geometr: Math.sqrt(x.abs*y.abs)}
end

.dz6(x, y) ⇒ Object



25
26
27
# File 'lib/mathsuite.rb', line 25

def dz6(x, y)
  { gipotenuza: Math.sqrt(x**2+y**2), square: (x.abs*y.abs)/2}
end

.dz7(v1, t1, v2, t2) ⇒ Object



29
30
31
# File 'lib/mathsuite.rb', line 29

def dz7(v1, t1, v2, t2)
  { volume_M3: (v1+v2)/1000, temperature: (v1*1*t1+v2*1*t2)/(v1*1+v2*1) }
end

.dz77(n) ⇒ Object



181
182
183
184
# File 'lib/mathsuite.rb', line 181

def dz77(n)
  fact = n.downto(1).inject(:*)
  { n2: 2**n, fact: fact}
end

.dz8(n, r) ⇒ Object



33
34
35
# File 'lib/mathsuite.rb', line 33

def dz8(n, r)
  { Perimetr: r*Math.tan(360/(2*n))*2*n}
end

.dz9(r1, r2, r3) ⇒ Object



37
38
39
# File 'lib/mathsuite.rb', line 37

def dz9(r1, r2, r3)
  { resistance: (r1*r2*r3)/(r2*r3+r1*r3+r1*r2)}
end